wp_get_active_and_valid_plugins() WP 3.0.0

Click here to view original web page at wp-kama.ru

Получает массив путей к главным файлам активных плагинов.

Список активных плагинов функция получает из базы данных, из опций:

Каталогом для плагинов по умолчанию является wp-content/plugins. Его можно изменить через константы WP_PLUGIN_DIR и WP_PLUGIN_URL, определенные в файле wp-config.php.

Хуков нет.

Возвращает

Массив. Массив абсолютных путей к основным файлам активных плагинов.

Заметка: При обновлении или установке WordPress возвратится пустой список.

Использование

Примеры

#1 Пример работы функции

$list = wp_get_active_and_valid_plugins();

print_r( $list );

// Получим
Array (
	[0] => F:\server\www\example.com/wp-content/plugins/query-monitor/query-monitor.php
	[1] => F:\server\www\example.com/wp-content/plugins/advanced-custom-fields-pro/acf.php
	[2] => F:\server\www\example.com/wp-content/plugins/akismet/akismet.php
	[3] => F:\server\www\example.com/wp-content/plugins/crypto-currencies-live-charts/crypto-currencies-live-charts.php
	[4] => F:\server\www\example.com/wp-content/plugins/cryptocurrency-reviews/cryptocurrency-reviews.php
	[5] => F:\server\www\example.com/wp-content/plugins/cyr3lat/cyr-to-lat.php
	[6] => F:\server\www\example.com/wp-content/plugins/democracy-poll/democracy.php
	[7] => F:\server\www\example.com/wp-content/plugins/font-awesome-4-menus/n9m-font-awesome-4.php
	[8] => F:\server\www\example.com/wp-content/plugins/image-watermark/image-watermark.php
	[9] => F:\server\www\example.com/wp-content/plugins/luckywp-scripts-control/luckywp-scripts-control.php
	[10] => F:\server\www\example.com/wp-content/plugins/profunctions/profunctions.php
	[11] => F:\server\www\example.com/wp-content/plugins/tablepress/tablepress.php
	[12] => F:\server\www\example.com/wp-content/plugins/widget-logic/widget_logic.php
	[13] => F:\server\www\example.com/wp-content/plugins/wp-subscribe/wp-subscribe.php
)

Список изменений

function wp_get_active_and_valid_plugins() {
	$plugins        = array();
	$active_plugins = (array) get_option( 'active_plugins', array() );

	// Check for hacks file if the option is enabled.
	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {
		_deprecated_file( 'my-hacks.php', '1.5.0' );
		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );
	}

	if ( empty( $active_plugins ) || wp_installing() ) {
		return $plugins;
	}

	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false;

	foreach ( $active_plugins as $plugin ) {
		if ( ! validate_file( $plugin )                     // $plugin must validate as file.
			&& '.php' === substr( $plugin, -4 )             // $plugin must end with '.php'.
			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
			// Not already included as a network plugin.
			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) )
			) {
			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;
		}
	}

	/*
	 * Remove plugins from the list of active plugins when we're on an endpoint
	 * that should be protected against WSODs and the plugin is paused.
	 */
	if ( wp_is_recovery_mode() ) {
		$plugins = wp_skip_paused_plugins( $plugins );
	}

	return $plugins;
}

Cвязанные функции

Из метки: plugin (плагин)

Еще из раздела: Плагины, хуки