/** * Attempts to load a file and if so, puts its contents in an array as expected by Metaplate * * @param string $file File path. Can be relative to current theme or absolute. Must be .html or .htm * * @return array|void Returns an array 'html' => file contents if possible. */ public static function load($file) { add_filter('calderawp_file_locator_allow_extensions', function ($allowed, $context) { if (self::$context === $context) { $allowed = array('html', 'htm'); } return $allowed; }, 10, 2); $file = file_locator::locate($file, self::$context, true); if (is_string($file)) { return array('html' => array('code' => file_get_contents($file))); } }
/** * Return a file path or file contents, checking in child theme, then theme, then as an absolute file path. * * @since 1.0.0 * * @param string $file The file to attempt to load, either the full path or relative to currently active theme. * @param string $use_for Optional. A context flag that enables filtering allowed extensions via "calderawp_file_locator_allow_extensions" * @param bool $return_path_only Optional. If false, the default, the contents of the file are returned. If true, the path is returned. * * @return void|string File contents, or path if it was loaded. */ function calderawp_file_locator($file, $use_for = false, $return_path_only = false) { return \calderawp\file_locator\file_locator::locate($file, $return_path_only); }