• Resolved jayhoo

    (@jayhoo)


    Hello,

    I installed this plugin and want to add Tailwind to my Custom Theme (a blank theme https://underscores.me/)

    I already added th Scanner code into my functions.php file following this document https://wind.press/docs/integrations/custom-theme

    <?php

    /**
    * @param array $providers The collection of providers that will be used to scan the design payload
    * @return array
    */
    function register_my_theme_provider(array $providers): array {
    $providers[] = [
    'id' => 'uu_dam', // The id of this custom provider. It should be unique across all providers
    'name' => 'My Theme Scanner',
    'description' => 'Scans the current active theme and child theme',
    'callback' => 'scanner_cb_my_theme_provider', // The function that will be called to get the data. Please see the next step for the implementation
    'enabled' => \WindPress\WindPress\Utils\Config::get(sprintf(
    'integration.%s.enabled',
    'uu_dam' // The id of this custom provider
    ), true),
    ];

    return $providers;
    }
    add_filter('f!windpress/core/cache:compile.providers', 'register_my_theme_provider');

    and

    <?php

    function scanner_cb_my_theme_provider(): array {
    // The file with this extension will be scanned, you can add more extensions if needed
    $file_extensions = [
    'php',
    'js',
    'html',
    ];

    $contents = [];
    $finder = new \WindPressDeps\Symfony\Component\Finder\Finder();

    // The current active theme
    $wpTheme = wp_get_theme();
    $themeDir = $wpTheme->get_stylesheet_directory();

    // Check if the current theme is a child theme and get the parent theme directory
    $has_parent = $wpTheme->parent() ? true : false;
    $parentThemeDir = $wpTheme->parent()->get_stylesheet_directory() ?? null;

    // Scan the theme directory according to the file extensions
    foreach ($file_extensions as $extension) {
    $finder->files()->in($themeDir)->name('*.' . $extension);
    if ($has_parent) {
    $finder->files()->in($parentThemeDir)->name('*.' . $extension);
    }
    }

    // Get the file contents and send to the compiler
    foreach ($finder as $file) {
    $contents[] = [
    'name' => $file->getRelativePathname(),
    'content' => $file->getContents(),
    ];
    }

    return $contents;
    }

    But when i press Generate Cache button then it’s showing this notification:
    Error: Failed to generate cache

    Can you tell me what’s missing here?

    Thanks,
    Jay

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jayhoo

    (@jayhoo)

    I found the issue, we should be change

    $parentThemeDir = $wpTheme->parent()->get_stylesheet_directory() ?? null;

    to

    $parentThemeDir = $has_parent ? $wpTheme->parent()->get_stylesheet_directory() : null;
    Plugin Author Joshua Gugun Siagian

    (@suabahasa)

    Hi @jayhoo,

    Thank you, we have update our Docs with the change you suggest.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.