bsf_extract_product_id( string $path )

BSF extract Product ID.


Description


Parameters

$path

(string) (Required) Path.


Source

File: admin/bsf-core/index.php

	function bsf_extract_product_id( $path ) {
		$id            = false;
		$file          = rtrim( $path, '/' ) . '/admin/bsf.yml';
		$file_fallback = rtrim( $path, '/' ) . '/bsf.yml';

		if ( is_file( $file ) ) {
			$file = $file;
		} elseif ( is_file( $file_fallback ) ) {
			$file = $file_fallback;
		} else {
			return apply_filters( 'bsf_extract_product_id', $id, $path );
		}

		// Use of file_get_contents() - https://github.com/WordPress/WordPress-Coding-Standards/pull/1374/files#diff-400e43bc09c24262b43f26fce487fdabR43-R52.
		$filelines = file_get_contents( $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Reading local file is OK.
		if ( stripos( $filelines, 'ID:[' ) !== false ) {
			preg_match_all( '/ID:\[(.*?)\]/', $filelines, $matches );
			if ( isset( $matches[1] ) ) {
				$id = ( isset( $matches[1][0] ) ) ? $matches[1][0] : '';
			}
		}

		return apply_filters( 'bsf_extract_product_id', $id, $path );
	}


User Contributed Notes

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