timber / starter-theme

The "_s" for Timber: a dead-simple theme that you can build anything from
MIT License
811 stars 275 forks source link

FATAL error on timber/starter_theme 2.x autoload.php reference using wp-cli #145

Closed pgnd closed 7 months ago

pgnd commented 9 months ago

Failed to open stream: No such file or directory in /srv/wp.app/web/app/themes/timber_s/functions.php on line 8

I've timber 2x-dev installed on bedrock+composer installed WP 6.3.1

cd wp.app/
wp-cli core version
    6.3.1
wp-cli cli info
    OS:     Linux 6.4.15-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep  7 00:25:01 UTC 2023 x86_64
    Shell:  /bin/bash
    PHP binary:     /usr/bin/php
    PHP version:    8.2.10
    php.ini used:   /usr/local/etc/php8/php.ini
    MySQL binary:   /usr/bin/mysql
    MySQL version:  mysql  Ver 15.1 Distrib 10.11.5-MariaDB, for Linux (x86_64) using  EditLine wrapper
    SQL modes:
    WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
    WP-CLI vendor dir:      phar://wp-cli.phar/vendor
    WP_CLI phar path:       /srv/wp.app
    WP-CLI packages dir:
    WP-CLI cache dir:       /var/lib/wwwrun/.wp-cli/cache
    WP-CLI global config:
    WP-CLI project config:  /srv/wp.app/wp-cli.yml
    WP-CLI version: 2.8.1
composer show | grep timber
    timber/timber                                           2.x-dev 6ef7f69    Plugin to write WordPress them...

with

php -v
    PHP 8.2.10 (cli) (built: Aug 29 2023 15:31:38) (NTS gcc x86_64)
    Copyright (c) The PHP Group
    Zend Engine v4.2.10, Copyright (c) Zend Technologies
        with Zend OPcache v8.2.10, Copyright (c), by Zend Technologies
composer --version
    Composer version 2.6.3 2023-09-15 09:38:21

php autoload.php exists

ls -al vendor/autoload.php
    -rw-r--r-- 1 wwwrun www 771 Apr  7 09:20 vendor/autoload.php

timber_s is installed as a parent theme

cd web/app/themes/timber_s
git branch -a | grep \*
    * 2.x

git log -n1
      1 commit 186eca6377f214bf9fa88004b228ce43ade5ef86 (HEAD -> 2.x, origin/2.x)
      2 Merge: 1254c2f 244d315
      3 Author: Lukas Gächter <lukas.gaechter@mind.ch>
      4 Date:   Mon Jul 31 14:26:24 2023 +0200
      5
      6     Merge pull request #142 from timber/2.x-fix-tests

cd ../mychild-timber/
grep Template style.css
    Template:        timber_s

wp-cli exec FAILs with FATAL error

wp-cli
    Warning: require_once(/srv/wp.app/web/app/themes/timber_s/vendor/autoload.php): Failed to open stream: No such file or directory in /srv/wp.app/web/app/themes/timber_s/functions.php on line 8
    Fatal error: Uncaught Error: Failed opening required '/srv/wp.app/web/app/themes/timber_s/vendor/autoload.php' (include_path='.:/usr/share/pear') in /srv/wp.app/web/app/themes/timber_s/functions.php:8
    Stack trace:
    #0 /srv/wp.app/web/wp/wp-settings.php(600): include()
    #1 phar:///opt/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1349): require('/optbapps/r...')
    #2 phar:///opt/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1267): WP_CLI\Runner->load_wordpress()
    #3 phar:///opt/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
    #4 phar:///opt/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
    #5 phar:///opt/wp-cli/wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
    #6 phar:///opt/wp-cli/wp-cli.phar/php/boot-phar.php(20): include('phar:///opt...')
    #7 /opt/wp-cli/wp-cli.phar(4): include('phar:///opt...')
    #8 {main}
      thrown in /srv/wp.app/web/app/themes/timber_s/functions.php on line 8

checking @

https://github.com/timber/starter-theme/blob/186eca6377f214bf9fa88004b228ce43ade5ef86/functions.php#L8

EDITing

@ wp.app/web/app/themes/timber_s

EITHER

-   require_once __DIR__ . '/vendor/autoload.php';
+   require_once __DIR__ . '/../../../../vendor/autoload.php';

OR

-   require_once __DIR__ . '/vendor/autoload.php';
+   require_once ABSPATH . '../../vendor/autoload.php';

fixes the unfound reference FAIL

wp-cli
    NAME

      wp

    DESCRIPTION

      Manage WordPress through the command-line.

    SYNOPSIS

      wp <command>

    SUBCOMMANDS

      cache                        Adds, removes, fetches, and flushes the WP Object Cache object.
    ...

is that require needed? esp if addressed in child?

e.g., i've

cat web/app/themes/mychild-timber
    ...
    require_once get_stylesheet_directory() . '/inc/timberSetup.php';
    ...

cat web/app/themes/mychild-timber/inc/timberSetup.php
    ...
    $composer_autoload = ABSPATH . '../../vendor/autoload.php';
    if (file_exists($composer_autoload)) {
        require_once $composer_autoload;
        Timber\Timber::init();
    }

    /* Check for Timber load */
    if (!class_exists('Timber')) {
        add_action(
    ...

tbh, @gchtr , i'm, unclear if this is 'just' a timber theme issue, and/or wp-cli

see

"WP-CLI's use of composer is interfering with site's usage of composer"
 https://github.com/wp-cli/wp-cli/issues/4632

seems a clean fix belongs in the theme ... ?

szepeviktor commented 9 months ago

Hello @pgnd 👋🏻 This is a starter theme, a template. It expects you to install dependencies inside it.

If you install it as a dependency just delete line number 8.

szepeviktor commented 9 months ago

BTW I load Composer's autoloader from wp-config. https://github.com/szepeviktor/wordpress-website-lifecycle/blob/f893c9b687ddf0ea1d448714cda2d2362c80d567/wp-config/wp-config.php#L32-L34

pgnd commented 9 months ago

@szepeviktor

This is a starter theme, a template. It expects you to install dependencies inside it.

sure/understood.

it's also the closet thing I've found to a subthemable parent theme that's timber2-ready.

other than this^^ glitch, it works great here in a parent/child steup. ideally , requiring no mods to the parent.

a little logic ... adding multiple search paths, perhaps? ... would be perhaps useful. i don't think it'd break any other functionality (yet)

Levdbas commented 7 months ago

Hi @pgnd , this would require more FS reads and we want to keep that to a minimum. Since this is a starter theme we always recommend people to modify it to their own needs. So we are not going to implement multiple search paths, sorry.