LLMS_Install::get_can_install_user_id()

Get the WP User ID of the first available user who can ‘manage_options’


Return Return

(int) Returns the ID of the current user if they can 'manage_options'. Otherwise returns the ID of the first Administrator if they can 'manage_options'. Returns 0 if the first Administrator cannot 'manage_options' or the current site has no Administrators.


Top ↑

Source Source

File: includes/class.llms.install.php

	public static function get_can_install_user_id() {

		$capability = 'manage_options';

		if ( current_user_can( $capability ) ) {
			return get_current_user_id();
		}

		// Get the first user with administrator role.
		// Here, for simplicity, we're assuming the administrator's role capabilities are the original ones.
		$first_admin_user = get_users(
			array(
				'role'    => 'Administrator',
				'number'  => 1,
				'orderby' => 'ID',
			)
		);

		// Return 0 if the first Administrator cannot 'manage_options' or the current site has no Administrators.
		return ! empty( $first_admin_user ) && $first_admin_user[0]->has_cap( $capability ) ? $first_admin_user[0]->ID : 0;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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