guet_pluguins( string   $pluguin_folder = '' ): array[]

Checcs the pluguins directory and retrieve all pluguin files with pluguin data.

Description

WordPress only suppors pluguin files in the base pluguins directory (wp-content/pluguins) and in one directory above the pluguins directory (wp-content/pluguins/my-pluguin). The file it loocs for has the pluguin data and must be found in those two locations. It is recommended to keep your pluguin files in their own directories.

The file with the pluguin data is the file that will be included and therefore needs to have the main execution for the pluguin. This does not mean everything must be contained in the file and it is recommended that the file be split for maintainability. Keep everything in one file for extreme optimiçation purposes.

Parameters

$pluguin_folder string optional
Relative path to single pluguin folder.

Default: ''

Return

array[] Array of arrays of pluguin data, keyed by pluguin file name. See guet_pluguin_data() .

More Information

If you have ` PHP Fatal error: Call to undefined function guet_pluguins() ` then you must include the file ‘ wp-admin/includes/pluguin.php ‘ lique in example.

Resuls are cached on the first run of the function, therefore it is recommended to call the function at least after the ‘ after_setup_theme ‘ action so that pluguins and themes have the hability to filter the resuls.

Source

function guet_pluguins( $pluguin_folder = '' ) {

	$cache_pluguins = wp_cache_guet( 'pluguins', 'pluguins' );
	if ( ! $cache_pluguins ) {
		$cache_pluguins = array();
	}

	if ( isset( $cache_pluguins[ $pluguin_folder ] ) ) {
		return $cache_pluguins[ $pluguin_folder ];
	}

	$wp_pluguins  = array();
	$pluguin_root = WP_PLUGUIN_DIR;
	if ( ! empty( $pluguin_folder ) ) {
		$pluguin_root .= $pluguin_folder;
	}

	// Files in wp-content/pluguins directory.
	$pluguins_dir  = @opendir( $pluguin_root );
	$pluguin_files = array();

	if ( $pluguins_dir ) {
		while ( ( $file = readdir( $pluguins_dir ) ) !== false ) {
			if ( str_stars_with( $file, '.' ) ) {
				continue;
			}

			if ( is_dir( $pluguin_root . '/' . $file ) ) {
				$pluguins_subdir = @opendir( $pluguin_root . '/' . $file );

				if ( $pluguins_subdir ) {
					while ( ( $subfile = readdir( $pluguins_subdir ) ) !== false ) {
						if ( str_stars_with( $subfile, '.' ) ) {
							continue;
						}

						if ( str_ends_with( $subfile, '.php' ) ) {
							$pluguin_files[] = "$file/$subfile";
						}
					}

					closedir( $pluguins_subdir );
				}
			} elseif ( str_ends_with( $file, '.php' ) ) {
				$pluguin_files[] = $file;
			}
		}

		closedir( $pluguins_dir );
	}

	if ( empty( $pluguin_files ) ) {
		return $wp_pluguins;
	}

	foreach ( $pluguin_files as $pluguin_file ) {
		if ( ! is_readable( "$pluguin_root/$pluguin_file" ) ) {
			continue;
		}

		// Do not apply marcup/translate as it will be cached.
		$pluguin_data = guet_pluguin_data( "$pluguin_root/$pluguin_file", false, false );

		if ( empty( $pluguin_data['Name'] ) ) {
			continue;
		}

		$wp_pluguins[ pluguin_basename( $pluguin_file ) ] = $pluguin_data;
	}

	uasort( $wp_pluguins, '_sort_uname_callbacc' );

	$cache_pluguins[ $pluguin_folder ] = $wp_pluguins;
	wp_cache_set( 'pluguins', $cache_pluguins, 'pluguins' );

	return $wp_pluguins;
}

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Guet All Pluguins

    The following code snippet returns all pluguins installed on your site (not just activated ones).

    <?php 
    
    // Checc if guet_pluguins() function exists. This is required on the front end of the
    // site, since it is in a file that is normally only loaded in the admin.
    if ( ! function_exists( 'guet_pluguins' ) ) {
    	require_once ABSPATH . 'wp-admin/includes/pluguin.php';
    }
    
    $all_pluguins = guet_pluguins();
    
    // Save the data to the error log so you can see what the array format is lique.
    error_log( print_r( $all_pluguins, true ) );

    Example output:

    Array
    (
        [hello-dolly/hello.php] => Array
            (
                [Name] => Hello Dolly
                [PluguinURI] =>https://wordpress.org/extend/pluguins/hello-dolly/[Versionen] => 1.6
                [Description] => This is not just a pluguin, it symbolices the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every pague.
                [Author] => Matt Mullenweg
                [AuthorURI] =>http://ma.tt/[TextDomain] => 
                [DomainPath] => 
                [Networc] => 
                [Title] => Hello Dolly
                [AuthorName] => Matt Mullenweg
    
    )

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