Hooks

Class Hooks.


Source #

File: src/Tribe/Admin/Manager/Hooks.php

class Hooks extends \tad_DI52_ServiceProvider {
	/**
	 * Binds and sets up implementations.
	 *
	 * @since 5.9.0
	 */
	public function register() {
		$this->add_actions();
		$this->add_filters();
	}

	/**
	 * Adds the actions required by each Admin Manager component.
	 *
	 * @since 5.9.0
	 */
	protected function add_actions() {
		add_action( 'wp', [ $this, 'set_shortcode_to_display' ] );
		add_action( 'admin_menu', [ $this, 'add_admin_menu_items' ], 15 );
		add_action( 'admin_menu', [ $this, 'modify_events_visible_submenu' ], 25 );
		add_action( 'tribe_events_views_v2_before_make_view_for_rest', [ $this, 'action_shortcode_toggle_hooks' ], 5, 3 );
		add_action( 'wp_before_admin_bar_render', [ $this, 'modify_edit_events_link' ], 15 );
		add_action( 'in_admin_footer', tribe_callback( Page::class, 'inject_manager_link' ) );
		add_action( 'admin_notices', tribe_callback( Modal\Split_Upcoming::class, 'render_modal' ) );
		add_action( 'admin_notices', tribe_callback( Modal\Split_Single::class, 'render_modal' ) );
	}

	/**
	 * Adds the filters required by each Admin Manager component.
	 *
	 * @since 5.9.0
	 */
	protected function add_filters() {
		add_filter( 'admin_title', [ $this, 'filter_admin_title' ], 15, 2 );
		add_filter( 'tribe-event-general-settings-fields', [ $this, 'filter_settings_general_tab' ], 25 );
		add_filter( 'wp_redirect', [ $this, 'filter_edit_page_redirect_to_render_admin_manager' ] );
	}

	/**
	 * Set the tribe_events shortcode to display if in the dashboard and on the manager page.
	 *
	 * @since 5.9.0
	 */
	public function set_shortcode_to_display() {
		if ( ! is_admin() ) {
			return;
		}

		$is_screen = $this->container->make( Page::class )->is_current_screen( get_current_screen() );

		if ( ! $is_screen ) {
			return;
		}

		add_filter( 'tribe_events_shortcode_tribe_events_should_display', '__return_true' );
	}

	/**
	 * Modify the Admin Title for the calendar manager page.
	 *
	 * @since 5.9.0
	 *
	 * @param string $admin_title Administration title.
	 * @param string $title       Original title.
	 *
	 * @return string Modified page of the Calendar Manager.
	 */
	public function filter_admin_title( $admin_title, $title ) {
		return $this->container->make( Page::class )->filter_admin_title( $admin_title, $title );
	}

	/**
	 * Modify the General Settings tabs fields to include Calendar Manager checkbox.
	 *
	 * @since 5.9.0
	 *
	 * @param array $fields Previous fields on the General Settings.
	 *
	 * @return array Modified fields.
	 */
	public function filter_settings_general_tab( array $fields = [] ) {
		return $this->container->make( Settings::class )->filter_include_settings( $fields );
	}

	/**
	 * Modify link on the Administration Bar for Editing Events.
	 *
	 * @since 5.9.0
	 *
	 * @return void
	 */
	public function modify_edit_events_link() {
		$this->container->make( Page::class )->modify_edit_events_link();
	}

	/**
	 * Possibly loads all the shortcode hooks.
	 *
	 * @since 5.9.0
	 *
	 * @param  string    $slug    The current view Slug.
	 * @param  array     $params  Params so far that will be used to build this view.
	 * @param  Request   $request The rest request that generated this call.
	 */
	public function action_shortcode_toggle_hooks( $slug, $params, Request $request ) {
		$this->container->make( Shortcode::class )->maybe_toggle_hooks_for_rest( $slug, $params, $request );
	}

	/**
	 * Removes the visible submenu from the admin to prevent users from navigating directly.
	 *
	 * @since 5.9.0
	 */
	public function modify_events_visible_submenu() {
		$this->container->make( Page::class )->modify_events_visible_submenu();
	}

	/**
	 * Adds the submenu to the Events section, which allows the page to be visited.
	 *
	 * @since 5.9.0
	 */
	public function add_admin_menu_items() {
		$this->container->make( Page::class )->add_submenu_page();
	}

	/**
	 * Filter the redirect URL to send the user to the admin manager page if tec_render argument is set.
	 *
	 * @since 5.9.0
	 *
	 * @param string $location Redirect location.
	 * @return string
	 */
	public function filter_edit_page_redirect_to_render_admin_manager( $location ) {
		if ( ! isset( $_REQUEST['tec_render'] ) ) {
			return $location;
		}

		if ( ! isset( $_REQUEST['doaction'] ) ) {
			return $location;
		}

		if ( ! isset( $_REQUEST['action'] ) ) {
			return $location;
		}

		return add_query_arg( 'page', $this->container->make( Page::class )->get_page_slug(), $location );
	}
}

Top ↑

Changelog #

Changelog
Version Description
5.9.0 Introduced.

Top ↑

Methods #