Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
    Hi, im new to WP Emerge and im using the starter theme, are there any additional docs/examples that I can follow to properly setup controllers and views? Having some trouble with that at the moment.
    Atanas Angelov

    Hi @asavchyn5
    Starter Theme docs are here: https://docs.wpemerge.com/#/starter-theme/overview
    Framework docs (controllers, views, examples) are here: https://docs.wpemerge.com/#/framework/overview

    There's a full example here: https://docs.wpemerge.com/#/framework/0-to-100-setup
    Since you're using the theme you can skip to "Making Something Useful" - https://docs.wpemerge.com/#/framework/0-to-100-setup?id=making-something-useful

    Hi @atanas-dev , Urgent Help Needed , some of my custom routes are returning 404 but the controller is rendering the content normally, http headers 404 . Route::url( 'cart' ) ->group( function () { Route::get() ->url( '/' ) ->handle( 'CartController@index' );
    Atanas Angelov
    URLs that WordPress does not recognize will still report a 404
    You should be able to override the status header but it's best to have content in WordPress that represents that url
    how to override the status ?
    Atanas Angelov
    in the controller when you return a view change it to this:
    return \WPEmerge\view( '...' )
        ->withStatus( 200 );
    Again, I suggest you create a page and hook the route to that instead:
    1. Create a Cart page
    2. Change route to:
      Route::get()->where( 'post_id', HARDCODED_ID_OR_OPTION_VALUE )->handle( 'CartController@index' );
    This way you have content inside WordPress so no 404 and any plugins you use will have content to associate their settings to (e.g. SEO plugins having something to associate their fields and front end output to)
    @atanas-dev thanks a lot
    Atanas Angelov
    Luc D
    hey @atanas-dev I cannot install WPEmerge-theme anymore. There's a yarn error on install. I don't know if the transcript may go here, since it's a rather big chunk of text... If it doesn't, I'll open a ticket on github...

    ```The command "yarn run build" failed.

    Exit Code: 2(Misuse of shell builtins)

    Working directory: /Users/arthos/Sites/dev/wp-content/themes/arthos


    yarn run v1.19.1
    $ cross-env NODE_ENV=production webpack --colors --config resources/build/webpack.production.js
    Hash: b9f6df49a7546dd997c6
    Version: webpack 4.32.2
    Time: 10730ms
    Built at: 27/11/2019 14:29:01
    7 assets
    Entrypoint theme = theme.js
    Entrypoint admin = admin.js styles/admin.css
    Entrypoint login = login.js styles/login.css
    Entrypoint editor = editor.js
    [2] ./config.json 1.1 KiB {0} {1} {2} {3} [built]
    [8] (webpack)/buildin/global.js 472 bytes {3} [built]
    [31] ./resources/scripts/theme/index.js 291 bytes {3} [built]
    [32] ./resources/images/favicon.ico 75 bytes {3} [built]
    [123] ./resources/scripts/admin/index.js 221 bytes {0} [built]
    [124] ./resources/scripts/login/index.js 221 bytes {2} [built]
    [125] ./resources/scripts/editor/index.js 222 bytes {1} [built]
    [126] ./resources/styles/theme/index.scss 2.65 KiB [built] [failed] [1 error]
    [127] ./resources/styles/admin/index.scss 41 bytes [built]
    [129] ./resources/styles/login/index.scss 41 bytes [built]
    [130] ./resources/styles/editor/index.scss 2.65 KiB [built] [failed] [1 error]

    + 120 hidden modules

    ERROR in ./resources/styles/theme/index.scss
    Module build failed (from ./node_modules/extract-text-webpack-plugin/dist/loader.js):
    ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js):
    Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (79)
    For more information on which environments are supported please see:
    at module.exports (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/node-sass/lib/binding.js:13:13)
    at Object.<anonymous> (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/node-sass/lib/index.js:14:35)
    at Module._compile (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1103:10)
    at Module.load (internal/modules/cjs/loader.js:914:32)
    at Function.Module._load (internal/modules/cjs/loader.js:822:14)
    at Module.require (internal/modules/cjs/loader.js:956:19)
    at require (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at Object.sassLoader (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/sass-loader/lib/loader.js:46:72)
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/webpack/lib/NormalModule.js:302:20
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at runSyncOrAsync (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at iterateNormalLoaders (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at runSyncOrAsync (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
    at iterateNormalLoaders (/Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/loader-runner/lib/LoaderRunner.js:205:4
    at /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:73:15
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
    @ ./resources/styles/theme/index.scss
    ... ```

    that's not complete, of course.
    what kind of info do you need to reproduce that ? npm version ? anything else ?
    Atanas Angelov
    Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime (79)
    Have you copied the node_modules directory from somewhere else or installed them from a virtual machine/docker?
    Your best bet is to run this to reinstall your node modules:
    rm -rf node_modules && yarn && yarn build
    Luc D
    I am on MacOS Catalina, yes ; I use Valet+ (https://github.com/weprovide/valet-plus) which is an evolution of Laravel Valet to serve my local sites...
    it's a fresh install, right from MacOS
    Atanas Angelov
    Let me know if the above snippet works
    Luc D
    it's rebuilding, i'll tell you
    ➜ arthos rm -rf node_modules && yarn && yarn build
    yarn install v1.19.1
    [1/5] 🔍 Validating package.json...
    [2/5] 🔍 Resolving packages...
    [3/5] 🚚 Fetching packages...
    [4/5] 🔗 Linking dependencies...
    [5/5] 🔨 Building fresh packages...
    [8/9] ⠠ node-sass
    [2/9] ⠐ fsevents
    [-/9] ⠐ waiting...
    [-/9] ⠐ waiting...
    error /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/node-sass: Command failed.
    Exit code: 1
    Command: node scripts/build.js
    Directory: /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/node-sass
    Building: /usr/local/Cellar/node/13.1.0/bin/node /Users/arthos/Sites/dev/wp-content/themes/arthos/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
    gyp info it worked if it ends with ok
    gyp verb cli [...
    so the problem comes from node-sass ? i'm fucked...
    Atanas Angelov
    do you have a yarn.lock file?
    Yup, seems they have problems with Catalina support but their latest version should work
    Luc D
    yep, there is a yarn.lock
    Atanas Angelov
    copy the line from yarn.lock that states the node-sass version
    Luc D
    version "4.12.0"
    resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.12.0.tgz#0914f531932380114a30cc5fa4fa63233a25f017"
    integrity sha512-A1Iv4oN+Iel6EPv77/HddXErL2a+gZ4uBeZUy+a8O35CFYTXhgA8MgLCWBtwpGZdCvTvQ9d+bQxX/QC36GDPpQ==
    async-foreach "^0.1.3"
    chalk "^1.1.1"
    cross-spawn "^3.0.0"
    gaze "^1.0.0"
    get-stdin "^4.0.1"
    glob "^7.0.3"
    in-publish "^2.0.0"
    lodash "^4.17.11"
    meow "^3.7.0"
    mkdirp "^0.5.1"
    nan "^2.13.2"
    node-gyp "^3.8.0"
    npmlog "^4.0.0"
    request "^2.88.0"
    sass-graph "^2.2.4"
    stdout-stream "^1.4.0"
    "true-case-path" "^1.0.2"
    Matheus Paiva
    Hey, I already had this kind of problem in other projects. The problem is with node-sass, that does not work with some versions of node. So, try to upgrade/downgrade your node/npm version.
    Atanas Angelov
    latest node-sass (4.13) requires node >= 10 so your node is probably older as it installs node-sass 4.9 instead of the latest one
    so as @matepaiva said, you need to upgrade your node to 10+
    12 which is the latest LTS is probably a good choice 12 is a bit recent (October) so you may want 10 instead to be on the safe side that all webpack plugins work properly
    Luc D
    ➜ ~ node -v
    Atanas Angelov
    k, try yarn upgrade node-sass
    Luc D
    ok, after upgrading node-sass, it seems to work fine. thanks guys.
    Matheus Paiva
    hello @atanas-dev, everything ok? Sorry to bother you here, but are you responsible for carbon-fields package? If not, could you recommend someone? I am asking this here because there are months that nobody answers in carbon fields gitter. Thanks in advance
    Luc D

    hey all, I'm trying to create an easier way to include partials, and according to what I've read, it goes by the creation of a Controller, so I've read the dedicated page, and tried my hand at the example given.
    /app/config.php :

    return [
         * Array of service providers you wish to enable.
        'providers'           => [

    /app/src/View/ViewComposersServiceProvider.php :

    namespace App\ViewComposers;
    use WPEmerge\Facades\View;
    use WPEmerge\ServiceProviders\ServiceProviderInterface;
    class ViewComposersServiceProvider implements ServiceProviderInterface {
         * {@inheritDoc}
        public function register( $container ) {}
         * {@inheritDoc}
        public function bootstrap( $container ) {
            View::addComposer( 'theme/partials/articles-accueil', function( $view ) {
                $view->with( [
                    'news'  => new \WP_Query( [
                        'posts_per_page' => 11,
                    ] ),
                ] );
            } );

    /theme/partials/articles-accueil.php :

    while( $news->have_posts() ) : $news->the_post(); ?>
    <article class="article">
        if( has_post_thumbnail() ):
        endif; ?>
        <a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a>
    enwhile; wp_reset_postdata(); ?>

    But still, I have an error on front end, saying :
    Uncaught Exception: The following class does not implement ServiceProviderInterface: App\View\ViewComposersServiceProvider in /Users/arthos/Sites/dfid/wp-content/themes/dfid/vendor/htmlburger/wpemerge/src/Application/Application.php on line 195

    when clearly, I have declared the Service Provider in config.php and even composer dumpautoloaded and restarted yarn... What am I doing wrong ?

    Luc D
    Ok, got it. my providers declaration wasn't accurate. I don't have the error anymore (but the partial doesn't load yet, still looking for that).
    Luc D
    Well, I'm getting the gist of it, but I'm slow. Guess I need to upgrade my game about this kind of frameworks. I'll look it up, but if any of you has a preferred tutorial/lesson/anything that could help me understand the roles of Controllers, Composers, etc., be it about Laravel, Symfony, Sage or any other, I'd be glad if you'd share them. :)
    Atanas Angelov
    @matepaiva unfortunately no, I am no longer involved with the Carbon Fields project
    @LucArthos_gitlab did you manage to solve all of the problems?
    For WP Emerge composers, I have a small write up here: https://wpemerge.com/2019/01/24/view-composers-passing-data-and-staying-dry/
    In short:
    • Composers are used to provide data (variables/context) to view partials regardless of which view renders them.
    • Controllers are used to handle routes (validate requests, do database stuff etc.) and usually render a view as a response (optionally passing data which may be request-specific).
    Matheus Paiva
    @atanas-dev thanks for letting me know and sorry again to bother you here
    Luc D
    @atanas-dev yeah, I've read your write up (but since it's a bit old, it seems to have to be adapted, and I'm still quite new to this :) ). Yeah, I made it work, but since I tried many things, I'm not sure what worked and what is just noise that doesn't work (but doesn't go in the way).
    Let's say I want to make two partials, should I create two ViewComposers with unique names? Or can one be used in many ways, like the Controllers : PageController@home and PageController@paged, etc. ?
    Atanas Angelov
    One composer can compose many views, and a single view can be composed by many composers
    If you want to pass the same data to two different partials, use a single composer and pass the views as an array - ::addComposer( ['view1', 'view2'], 'ComposerClass' )
    If you want to pass different data then you need different composers (separate classes)
    (instead of composer classes you can also use anonymous functions, of course - matter of preference and brevity)
    Luc D
    thanks for the explanation, I'm going to get deeper into that.
    I wish you all guys a merry christmas!
    Fabry D
    How can i uninstall carbon-fields from wpemerge CLI ?
    Atanas Angelov

    Hi @fabryssd_gitlab , the CLI is a minor utility only meant to bootstrap you so it does not include uninstall steps (and they can get quite messy depending on how you change the installed packages).
    To completely remove Carbon Fields which you have installed via the CLI, you can do the following:

    1. composer remove htmlburger/carbon-fields
    2. Delete the app/setup/carbon-fields/ directory
    3. Edit app/helpers.php and remove the require statement that points to carbon-fields.php
    4. Edit app/hooks.php and remove all hooks which reference app_bootstrap_carbon_fields, app_bootstrap_carbon_fields_register_fields and app_filter_carbon_fields_google_maps_api_key
    5. Edit app/setup/widgets.php and remove register_widget( App\Widgets\Carbon_Rich_Text_Widget::class );

    If you only want to disable Carbon Fields, rather than removing it completely, you should only comment out the filters in step 4 and step 5 (ignoring the rest of the steps).

    Fabry D
    Thank You :) :)