Tribe__Events__Community__Tickets__Main::give_subscribers_upload_files_cap( $all_caps,  $caps,  $args )

Add the upload_files capability to a user when they are uploading files

Topics


Source #

File: src/Tribe/Main.php

	public function give_subscribers_upload_files_cap( $all_caps, $caps, $args ) {
		// Bail if there isn't a cap or user_id
		if ( empty( $caps[0] ) || empty( $args[1] ) ) {
			return $all_caps;
		}

		$cap = $caps[0];
		$user_id = absint( $args[1] );

		if ( 'upload_files' !== $cap ) {
			return $all_caps;
		}

		// If the user isn't logged in, bail
		if ( ! is_user_logged_in() ) {
			return $all_caps;
		}

		// If the user isn't uploading media, bail
		if ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/async-upload.php' ) ) {
			return $all_caps;
		}

		// If the user is originating the request from the dashboard, bail
		if ( false !== strpos( $_SERVER['HTTP_REFERER'], '/wp-admin/' ) ) {
			return $all_caps;
		}

		$base_url = get_bloginfo( 'url' );

		// If the request did not come from the site, bail
		if ( ! preg_match( "@^{$base_url}@", $_SERVER['HTTP_REFERER'] ) ) {
			return $all_caps;
		}

		$all_caps['upload_files'] = true;

		return $all_caps;
	}