Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Atanas Angelov
    @atanas-dev
    There's no default view that WordPress tries to load during ajax requests. The empty value is passed for consistency.
    Calvin Alkan
    @calvinalkan

    got it. I'll strip it out in the container implementation since every controller, middleware, etc gets resolved automatically.

    Another thing, is there a way we could allow for the extension of the error handler in a custom service provider?
    So far there are only CsrfException and NotFoundException that we can catch when we push something through the HTTP-Kernal process

    protected function toResponse( $exception ) {
    
            // @codeCoverageIgnoreStart
    
            if ( $exception instanceof InvalidCsrfTokenException ) {
    
                wp_nonce_ays( '' );
    
            }
    
            // @codeCoverageIgnoreEnd
    
    
    
            if ( $exception instanceof NotFoundException ) {
    
                return $this->response_service->error( 404 );
    
            }
    
    
    
            return false;
    
        }
    Atanas Angelov
    @atanas-dev
    You are free to extend it or write your own to fit your needs and replace it in the container :) It wasn't meant as an extension point, rather a minimal useful handler that is replaceable.
    Calvin Alkan
    @calvinalkan
    Ahh , yea I did not think about replacing in the comtainer. Ty.
    Jennifer Eberlei
    @jennifer.eberlei_gitlab

    Hey there, if I wanted to add acf to wpemerge, would i do that with its own service provider? would that make sense?

    I was thinking that widgets, and sidebars, and menus and such are provided via a service provider so I was wondering if it would make sense to do the same for registering custom fields with acf

    Atanas Angelov
    @atanas-dev
    Sure :)
    Jennifer Eberlei
    @jennifer.eberlei_gitlab
    In the sense of the starter themes logic, what would be the best way to make page templates?
    eg. the index uses the default layout, which is in app.php but if I want to create different page templates, would I still create files in the root theme folder for eg. template-test.php and have the normal layout applied, but am able to differ parts?
    Atanas Angelov
    @atanas-dev
    If it's custom page templates, I would put them in views/. If it's core templates like index.php, page.php, single.php, archive.php etc. I would put them in the root of the theme.
    You are free to swap out parts, create multiple layouts or not use a layout at all for one, some or all of your templates. It's a preference thing and it's a way to not duplicate code that is shared between templates so it depends on your templates.
    David Towoju
    @davexpression

    Hi, thanks for this plugin/framework.
    I keep getting "Unknown named parameter $menu"

    \App::route()->get()->where( 'admin', 'top-level-slug' )->handle( 'Controller@index' );

    Please help

    David Towoju
    @davexpression
    @atanas-dev
    Atanas Angelov
    @atanas-dev
    Hi @davexpression , at the very least I'm going to need the stack trace in order to help.
    Jennifer Eberlei
    @jennifer.eberlei_gitlab

    Hi, I tried to add woocommerce styles to the theme seperately from admin|frontend|login and edited the config.json and the AssetsServiceProvider.php like this:
    config.json

      "bundles": [
        "frontend",
        "admin",
        "login",
        "editor",
        "woocommerce"
      ],

    AssetsServiceProvider.php:

    /**
         * Enqueue woocommerce assets.
         *
         * @return void
         */
        public function enqueueWoocommerceAssets() {
            // Enqueue scripts.
            \Racom::core()->assets()->enqueueScript(
                'theme-woocommerce-js-bundle',
                \Racom::core()->assets()->getBundleUrl( 'woocommerce', '.js' ),
                [ 'jquery' ],
                true
            );
    
            // Enqueue styles.
            $style = \Racom::core()->assets()->getBundleUrl( 'woocommerce', '.css' );
    
            if ( $style ) {
                \Racom::core()->assets()->enqueueStyle(
                    'theme-woocommerce-css-bundle',
                    $style
                );
            }
    
            // Enqueue theme's style.css file to allow overrides for the bundled styles.
            \Racom::core()->assets()->enqueueStyle( 'theme-woocommerce-styles', get_template_directory_uri() . '/woocommerce.css' );
        }
    but only the woocommerce.js is being processed on yarn build, i don't get a theme-woocommerce.css even though I created the corresponding files in ressources/styles/woocommerce/index.scss
    so I wonder if I missed a configuration?
    I looked into the webpack build files and could't find any hint on where else I would have to configure
    image.png
    Atanas Angelov
    @atanas-dev
    Could you paste the contents of your woocommerce.js file? On the top of my head the most likely cause is that your css/scss is not imported in it.
    Branislav Stojanovic
    @djex808

    @atanas-dev Great work and thanks a lot for the framework. Looking forward to use it on my projects. Can somebody help me with why I am getting "Unknown named parameter $post_id" when post_id has been matched in web.php? Same for post_slug, post_status...

    Error thrown with message "Unknown named parameter $post_id"

    #20 Error in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:177
    #19 call_user_func_array in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:177
    #18 WPEmerge\Kernels\HttpKernel:executeHandler in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:205
    #17 WPEmerge\Kernels\HttpKernel:WPEmerge\Kernels\{closure} in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:40
    #16 WPEmerge\Kernels\HttpKernel:executeMiddleware in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:44
    #15 WPEmerge\Kernels\HttpKernel:WPEmerge\Middleware\{closure} in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Input/OldInputMiddleware.php:44
    #14 WPEmerge\Input\OldInputMiddleware:handle in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:53
    #13 call_user_func_array in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:53
    #12 WPEmerge\Kernels\HttpKernel:executeMiddleware in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:44
    #11 WPEmerge\Kernels\HttpKernel:WPEmerge\Middleware\{closure} in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Flash/FlashMiddleware.php:40
    #10 WPEmerge\Flash\FlashMiddleware:handle in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:53
    #9 call_user_func_array in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Middleware/ExecutesMiddlewareTrait.php:53
    #8 WPEmerge\Kernels\HttpKernel:executeMiddleware in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:206
    #7 WPEmerge\Kernels\HttpKernel:run in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:237
    #6 WPEmerge\Kernels\HttpKernel:handle in /Users/banestojanovic/Code/Manastiri/podmaine/wp-content/themes/podmaine/vendor/htmlburger/wpemerge/src/Kernels/HttpKernel.php:332
    #5 WPEmerge\Kernels\HttpKernel:filterTemplateInclude in /Users/banestojanovic/Code/Manastiri/podmaine/wp-includes/class-wp-hook.php:292
    #4 WP_Hook:apply_filters in /Users/banestojanovic/Code/Manastiri/podmaine/wp-includes/plugin.php:212
    #3 apply_filters in /Users/banestojanovic/Code/Manastiri/podmaine/wp-includes/template-loader.php:104
    #2 require_once in /Users/banestojanovic/Code/Manastiri/podmaine/wp-blog-header.php:19
    #1 require in /Users/banestojanovic/Code/Manastiri/podmaine/index.php:17
    #0 require in /Users/banestojanovic/.composer/vendor/laravel/valet/server.php:219
    Atanas Angelov
    @atanas-dev
    Hi @djex808 ,
    This looks like a PHP 8 issue - do you mind sharing your route definition that triggers this error?
    Branislav Stojanovic
    @djex808
    @atanas-dev You were completely right as it was indeed PHP 8 issue. I forgot to change the PHP version in valet - didn't even knew that I could do it there to be honest and it kept loading version 8 while terminal kept displaying 7.4.16. Sorry for the trouble :)
    Atanas Angelov
    @atanas-dev
    No worries - while PHP 8 is still not officially supported it should be so in the near future.
    David Towoju
    @davexpression

    Hi @davexpression , at the very least I'm going to need the stack trace in order to help.

    It's a PHP 8 issue, it works in PHP 7

    Calvin Alkan
    @calvinalkan

    @atanas-dev Hello Atanas, I can't get JSON responses to work for web request. The header is always empty. I debugged the entire HTTP Kernel.

    For example:

    App::json(['foo' => 'bar'])

    renders correctly in the browser. But the header is empty. Ie content type is not set to application/json altought the kernel supposedly called `sentHeaders()``

    Atanas Angelov
    @atanas-dev

    Hi @calvinalkan m

    Just to be absolutely sure the header is missing, could you please run this and paste the results:
    curl -i YOUR_JSON_ROUTE_URL

    Calvin Alkan
    @calvinalkan
    Hi @atanas-dev . It was a weird issue with some chrome extension I had installed that for some reason in chrome dev tools headers where not reported and that prevented the json form being rendered as json. curl -i gives the correct output and Mozilla also renders it as json. All good :)
    Calvin Alkan
    @calvinalkan
    @atanas-dev I think it might be worth adding to the docs, that in order for admin routes to work that one has to define a callback in add_menu_page
    // This will not work
    add_menu_page( 'test', 'test' , 'manage_options', 'test' );
    
    // Forth parameter is optional in Wordpress but its needed to work correctly
    add_menu_page( 'test', 'test' , 'manage_options','test',  function () {
    
                    // Nothing.
    
                });
    If you skip this Wordpress will not fire the hooks wpemerge relies on admin requests
    Atanas Angelov
    @atanas-dev
    This message was deleted
    Interesting - I'll look into it
    Calvin Alkan
    @calvinalkan

    The reason for this is that inside wp-admin/admin.php Wordpress checks if there is a hook callback registered for the current plugin page. If no hook is present it takes a different path inside the gigantic if elseif statement that wp-admin/admin.php is.

    Instead of dispatching the normal hooks wordpress then tries to load the content from a plugin file and if it cant find any matching file an error is thrown.

    And that hook only gets added if you add a callback to add_menu_page. Annoying.
    Calvin Alkan
    @calvinalkan

    @atanas-dev Can you explain what is ment by this in the docs

    "You should use query() on routes which do not match any valid WordPress URL or your WP Query will consider the request as a 404 - Not Found. You can find more information on this in the dedicated Query API blog post."

    What is considered a "valid Wordpress Url"
    Calvin Alkan
    @calvinalkan

    Am I right that the only reason for using query() is to have to global WP_QUERY query posts correctly?.

    Because thats the only use case I can see. If I dont need WP_QUERY ( which I dont ) I cant see any benefit over just composing everything with controllers and views.

    Atanas Angelov
    @atanas-dev
    Basically, yes.
    There's benefit in having custom URLs be associated with a given post in the case where you want to not have to do extra work for meta/SEO/third party plugin integrations to work on your custom URL.
    There's also the use case of modifying a query for an archive page to show a subset of the posts based on some arbitrary custom logic, for example.
    You could do a /random endpoint that uses ->query() to make the global $wp_query load a random post, for example. While not practical it just shows that there are some extra cases where it can be useful.
    Calvin Alkan
    @calvinalkan

    I see, this then also means that any conditions that use WP_QUERY like post_id condition or post_type condition only work when using query() in the route.

    Which makes sense. Thanks for the clarification

    Atanas Angelov
    @atanas-dev
    No, quite the opposite actually. Conditions that rely on WP_Query (post_id, post_type etc.) can't have ->query() called on them because the conditions require the query to have been executed in order to match (i.e. you can't test against the current post id if the main query hasn't resolved what the current post is yet).
    By default, ->query() usage is limited to the url route condition only as that condition can be evaluated before the main WP_Query has executed.
    Here's an example of what a normal post_id route looks like:
    App::route()->any()->where( 'post_id', get_option( 'my_special_page_id' ) )->handle( 'MyController::myMethod' );
    Calvin Alkan
    @calvinalkan
    Yea, I misphrased my thoughts a bit. I ment that all of these conditions will not work if the url you are routing to is not a "normal" Wordpress URL
    Atanas Angelov
    @atanas-dev
    Yep :)
    except is_404 I guess :D
    Calvin Alkan
    @calvinalkan
    :D

    the condition

    \App::route()->get()->where( 'query_var', 's' )->handle( $handler );

    Only matches default query vars defined in WP_QUERY right?

    Something like this did not work for me for "non WP Urls".

    https//example.com/page?foo='bar'

    Atanas Angelov
    @atanas-dev
    'query_var' uses get_query_var() so it matches its' behavior
    Calvin Alkan
    @calvinalkan

    got it.

    Im customizing wpemerge more and more to fit my own needs for a big project.

    Im very curious about one thing. When you generate an url condition why do you sha1 the placeholders?

    Atanas Angelov
    @atanas-dev
    Honestly it's been quite some time since I wrote that so I can't tell from the top of my head. Most likely, to avoid preg_quote()-ing the special characters in the parameter syntax used in the url at that stage
    Calvin Alkan
    @calvinalkan
    @atanas-dev
    have you ever considered more performant regex routers like FastRoute which would built the regex in one shot instead of all individually or do you think performance gains would be non noticeable respecting all the WP overhead anyway?