init_bsf_core()

Init BSF Core


Description


Source

File: admin/bsf-core/index.php

	function init_bsf_core() {

		$plugins      = get_plugins();
		$themes       = wp_get_themes();
		$bsf_products = array();

		$bsf_authors = apply_filters(
			'bsf_authors_list',
			array(
				'Brainstorm Force',
			)
		);

		foreach ( $plugins as $plugin => $plugin_data ) {
			if ( in_array( trim( $plugin_data['Author'] ), $bsf_authors, true ) ) {
				$plugin_data['type']     = 'plugin';
				$plugin_data['template'] = $plugin;
				$plugin_data['path']     = dirname( realpath( WP_PLUGIN_DIR . '/' . $plugin ) );
				$id                      = bsf_extract_product_id( $plugin_data['path'] );
				if ( false !== $id ) {
					$plugin_data['id'] = $id;
				} // without readme.txt filename
				array_push( $bsf_products, $plugin_data );
			}
		}

		foreach ( $themes as $theme => $theme_data ) {
			$temp         = array();
			$theme_author = trim( $theme_data->display( 'Author', false ) );
			if ( 'Brainstorm Force' === $theme_author ) {
				$temp['Name']        = $theme_data->get( 'Name' );
				$temp['ThemeURI']    = $theme_data->get( 'ThemeURI' );
				$temp['Description'] = $theme_data->get( 'Description' );
				$temp['Author']      = $theme_data->get( 'Author' );
				$temp['AuthorURI']   = $theme_data->get( 'AuthorURI' );
				$temp['Version']     = $theme_data->get( 'Version' );
				$temp['type']        = 'theme';
				$temp['template']    = $theme;
				$temp['path']        = realpath( get_theme_root() . '/' . $theme );
				$id                  = bsf_extract_product_id( $temp['path'] );
				if ( false !== $id ) {
					$temp['id'] = $id;
				} // without readme.txt filename
				array_push( $bsf_products, $temp );
			}
		}

		$brainstrom_products = ( get_option( 'brainstrom_products' ) ) ? get_option( 'brainstrom_products' ) : array();

		// Remove the brainstorm products which no longer exist on site.
		if ( ! function_exists( 'get_plugins' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}

		$plugins = get_plugins();
		$themes  = search_theme_directories();

		if ( ! empty( $brainstrom_products ) ) {

			if ( isset( $brainstrom_products['plugins'] ) ) {

				foreach ( $brainstrom_products['plugins'] as $key => $value ) {

					if ( ! array_key_exists( $value['template'], $plugins ) ) {
						unset( $brainstrom_products['plugins'][ $key ] );
					}
				}
			}

			if ( isset( $brainstrom_products['themes'] ) ) {

				foreach ( $brainstrom_products['themes'] as $key => $value ) {

					if ( ! array_key_exists( $value['template'], $themes ) ) {
						unset( $brainstrom_products['themes'][ $key ] );
					}
				}
			}
		}

		// Update newly added brainstorm_products.
		if ( ! empty( $bsf_products ) ) {
			foreach ( $bsf_products as $key => $product ) {
				if ( ! ( isset( $product['id'] ) ) || '' === $product['id'] ) {
					continue;
				}
				if ( isset( $brainstrom_products[ $product['type'] . 's' ][ $product['id'] ] ) ) {
					$bsf_product_info = $brainstrom_products[ $product['type'] . 's' ][ $product['id'] ];
				} else {
					$bsf_product_info = array();
					do_action( 'brainstorm_updater_new_product_added' );
				}
				$bsf_product_info['template'] = $product['template'];
				$bsf_product_info['type']     = $product['type'];
				$bsf_product_info['id']       = $product['id'];
				$brainstrom_products[ $product['type'] . 's' ][ $product['id'] ] = $bsf_product_info;
			}
		}

		update_option( 'brainstrom_products', $brainstrom_products );
	}


User Contributed Notes

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