BP_Attachment::__construct( array|string $args = '' )

Construct Upload parameters.

Description

Parameters

$args

(array|string) (Optional)

  • 'original_max_filesize'
    (int) Maximum file size in kilobytes. Defaults to php.ini settings.
  • 'allowed_mime_types'
    (array) List of allowed file extensions (eg: array( 'jpg', 'gif', 'png' ) ). Defaults to WordPress allowed mime types.
  • 'base_dir'
    (string) Component's upload base directory. Defaults to WordPress 'uploads'.
  • 'action'
    (string) The upload action used when uploading a file, $_POST['action'] must be set and its value must equal $action wp_handle_upload() (required).
  • 'file_input'
    (string) The name attribute used in the file input. (required).
  • 'upload_error_strings'
    (array) A list of specific error messages (optional).
  • 'required_wp_files'
    (array) The list of required WordPress core files. Default: array( 'file' ).
  • 'upload_dir_filter_args'
    (int) 1 to receive the original Upload dir array in the Upload dir filter, 0 otherwise. Defaults to 0 (optional).

Default value: ''

Source

File: bp-core/classes/class-bp-attachment.php

	public function __construct( $args = '' ) {
		// Upload action and the file input name are required parameters.
		if ( empty( $args['action'] ) || empty( $args['file_input'] ) ) {
			return false;
		}

		// Sanitize the action ID and the file input name.
		$this->action     = sanitize_key( $args['action'] );
		$this->file_input = sanitize_key( $args['file_input'] );

		/**
		 * Max file size defaults to php ini settings or, in the case of
		 * a multisite config, the root site fileupload_maxk option
		 */
		$this->default_args['original_max_filesize'] = (int) wp_max_upload_size();

		$params = bp_parse_args( $args, $this->default_args, $this->action . '_upload_params' );

		foreach ( $params as $key => $param ) {
			if ( 'upload_error_strings' === $key ) {
				$this->{$key} = $this->set_upload_error_strings( $param );

			// Sanitize the base dir.
			} elseif ( 'base_dir' === $key ) {
				$this->{$key} = sanitize_title( $param );

			// Sanitize the upload dir filter arg to pass.
			} elseif ( 'upload_dir_filter_args' === $key ) {
				$this->{$key} = (int) $param;

			// Action & File input are already set and sanitized.
			} elseif ( 'action' !== $key && 'file_input' !== $key ) {
				$this->{$key} = $param;
			}
		}

		// Set the path/url and base dir for uploads.
		$this->set_upload_dir();
	}

Changelog

Changelog
Version Description
BuddyPress 2.4.0 Add the $upload_dir_filter_args argument to the $arguments array BuddyPress 2.4.0 Add the $upload_dir_filter_args argument to the $arguments array
BuddyPress 2.3.0 Introduced.

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.