funkhaus / fuxt-backend Goto Github PK
View Code? Open in Web Editor NEWA theme that turns WordPress into a true GraphQL powered Headless CMS. Optimized for the fuxt frontend boilerplate.
License: GNU General Public License v3.0
A theme that turns WordPress into a true GraphQL powered Headless CMS. Optimized for the fuxt frontend boilerplate.
License: GNU General Public License v3.0
On the ILA site, they had a bunch of custom post types, amsterdam
, paris
and antwerp
, We noticed that the "Preview" link from the editor wouldn't go to the correct auto-saved URL.
The solution was adding more hooks for these custom post types.
https://github.com/funkhaus/fuxt-backend/blob/master/functions/wp-functions.php#L207-L208
I would have thought that the generic rest_prepare_post
would have worked for custom post types too, but it seems it doesn't: WP-API/WP-API#2419
So we could generate these action names dynamically, but querying for public post types with this: https://developer.wordpress.org/reference/functions/get_post_types/
In the past, we've used this code to modify the Preview links in the WordPress dashboard to add some extra params to the URL, and to quickly toggle the draft post to published, and then back to draft.
https://github.com/funkhaus/fuxt-backend/blob/master/functions/wp-functions.php#L168-L209
This used to give the draft a real permalink, so we could query it using WP-GQL's nodeByUri
query type.
But it seems recently WP has made it so that "drafts" never get a permalink. So toggling between published and draft doesn't work anymore.
The solution to this needs two parts. One, the Preview link in WordPress needs to be correct, but also the WP-GQL nodeByUri
query needs to actually work too. So I think the best way to solve this is to figure out how to have WordPress allow permalinks on drafts, and hope that nodeByUri
works with that. Rather than creating some hack to the Preview button in the dashboard to have a fake link.
This is a GQL query that I was using to test, with a post saved as a draft testing
and the WP pretty permalink settings as /news/p/%postname%/
.
query News {
posts(first: 1, where: {status: DRAFT}) {
nodes {
id
uri
slug
}
}
nodeByUri(uri: "/news/p/testing/") {
id
uri
}
post(id: "/news/p/testing/ ", idType: URI) {
id
uri
}
}
I'd like to replace the "WordPress Events and News" widget with a "Funkhaus News" widget. It can look and behave the same, just pulls news from the Funkhaus blog.
Can use this feed:
https://api.funkhaus.us/?feed=rss
https://api.funkhaus.us/?feed=rss2
https://api.funkhaus.us/?feed=atom
Must fail nicely, meaning if the RSS feed goes away (because funkhaus site goes down or domain name changes) it shouldn't crash the site.
Probably worth doing this until we support comments?
https://keithgreer.dev/wordpress-code-completely-disable-comments-using-functions-php
Now that we have Gutenberg the "Force text editor" switch doesn't work.
Hello!
I'm trying to install fuxt with fuxt-backend.
I'm blocked at the plugin installation step by ACF. When using the auto-install, ACF pro can't be installed and throws this error:
Something went wrong with the plugin API.
I guess it's because I don't have a pro licence.
However, when I install the standard ACF plugin (non pro), either manually or through the plugin page, everything breaks instantly:
There has been a critical error on this website. Please check your site admin email inbox for instructions.
Is there a specific step I'm missing?
Thanks!
Is this project Open Source?
If it is what kind of license covers this plugin?
Getting an issue with SameSite Cookie Manager where it prevents me from logging into WordPress.
I believe this is likely an issue with the Plugin and not Fuxt. Although, I wanted to ask if anyone has experience anything similar?
What exactly is the plugin used for, is it a requirement?
First of all, thank you for this theme! Exactly what I needed.
I noticed a small bug, which only appears when I have this theme installed.
In the Gutenberg editor, when adding a text-list block and trying to hit the enter
key to add a new line, simply nothing happens. I also cannot create a new line manually with the mouse. The only way to fix this is to temporarly switch to another theme, add the lines I need in the Gutenberg editor, and then switch back to fuxt
.
This is a plugin we currently use: https://github.com/MikhailRoot/samesite-cookie-manager/archive/refs/heads/master.zip
When using SSR sites with GraphCDN, we need to set the domain for cookies to .example.com
, which isn't possible with Flywheel as they hard code the define() for COOKIE_DOMAIN
to be the "WordPress Address (URL)".
So, I'd like to bring that code into the /functions
directory, and upgrade it to use a settings field for the cookie domain. We have to be careful that we don't make it easy to allow the cookies to be set on a domain like "flywheelsites.com".
The way that schedule works is someone has to load wordpress and it checks the the schedule... but with Headless WordPress, no one ever hits wordpress unless you login to the dashboard...
Perhaps sites with wp-controls would work, as that does a single request to wp-gql endpont, but I am not sure...
This was discovered on Wolf.
Build a custom REST API endpoint that can be used to proxy anything. Be sure to whitelist domains and origin from the frontend URL (or localhost).
Maybe we use it as an endpoint that hits the IP stack API and keeps our API key hidden for SSG sites.
This currently would allow other frontends to edit content on the site. That is bad.
I think the real fix is to change the origin header check to allow origins that are: wordpress install location, frontend location and local host.
Would be helpful if we could use a loop = true
arg on the nextPage {}
and previousPage{}
page GQL nodes. It would then always give you the first/last when viewing the first or last item in a list.
This is the function that I updated to do it in gql-functions.php
, but we need to get the GQL query working.
/*
* Util function for adjacent page id
*
* Params: $page -> page object from wordpress
* Params: $direction -> Integer -1 or 1 indicating next or previous post
* returns adjacent page id
*/
function get_adjacent_page_id($page, $direction)
{
$args = [
"post_type" => $page->post_type,
"order" => "ASC",
"orderby" => "menu_order",
"post_parent" => $page->post_parent,
"fields" => "ids",
"posts_per_page" => -1,
];
$pages = get_posts($args);
$current_key = array_search($page->ID, $pages);
$output = 0;
if (isset($pages[$current_key + $direction])) {
// Next page exists
$output = $pages[$current_key + $direction];
}
if(!$output && $direction > 0) {
$output = $pages[0];
}
if(!$output && $direction < 0) {
$output = $pages[ array_key_last($pages) ];
}
return $output;
}
Currently we have a hard time allowing clients to upload SVGs (mostly used for logo walls of awards or their clients). There is some code that we have to uncomment in wp-functions.php to allow it. It's commented off by default because of the danger that allowing SVGs pose to CMS and for people that might not be aware that we've allowed them...
So, I think we should build a option into the theme that can be toggled on and off (off by default). It's should be on the "writing" options page I think.
We should also test out uploading all the different SVG types and see what works and doesn't. Because I'm not even sure the code we have in the theme currently is the correct way to do it.
So currently we have a custom resolver to get the next post, or page in a GQL query:
https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php#L141
https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php#L198
But when it comes to "next post" often we'd want to be able to set the params that the underlying WordPress functions allows for to get "next post in same category" : https://developer.wordpress.org/reference/functions/get_next_post/
$in_same_term = false
$excluded_terms = ''
$taxonomy = 'category'
Probably makes sense to "WP-GQL" style the naming convention here, and call it "termIn" rather than the "excluded_terms".
So I'd like to have some "resolver-arguments" for those settings:
https://www.wpgraphql.com/docs/graphql-resolvers/#resolver-arguments
So we could do this type of query on a post:
nextPost(inSameTerm: true, termNotIn: '1,2,3', taxonomy: 'tag') {
node {
id
title
}
}
Would be really helpful if we could allow those terms to be slugs also, so a termSlugNotIn
as another argument that could be something like termSlugNotIn: 'featured, uncategorized'
.
Now this it would also be really good if we could translate those same arguments for nextPage
queries. So I could get next page that had the same tags. This isn't something there is a native WordPress function for, but you can see that it wouldn't be too hard to allow for same arguments for nextPage.
https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php#L182
https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php#L275
Would be great if we could have a rule for a CPT that has parent equal to 0... Just so a field group can show up on all top-level pages.
The default "page" type gets some useful ACF location rules, specially the "Page parent" and "Page belongs to tree" rules. Would be great if these worked for any Custom Post type that was hierarchical.
Would be cool if we could have the server generate a GIF of the site scrolling and serve it as the OG tag site image... maybe this is better served by being made by the the frontend?
For example, like they do here:
Would be great if you could use " has child" as a ACF location rule. Would be useful for page structures like this:
- Cars
- - BMW
- - - i3 <-- This one should have the ACF field group
It appears that the nextPost and previousPost queries are returning null unexpectedly.
Here is the list of posts on Optic Sky:
The next/prevPost gql query should return the adjacent posts in that list (see arrow).
On the post detail page you can see they are both returning null:
Previously we had issues where the query returned random posts for previous or next, but this is a new error where random posts return null
for prev or next or both posts.
Seems like this is a known issue, it's the same problem described here.
Unfortunately that suggested fix doesn't solve the issue as we're already whitelisting both core/list
and core/list-item
in gutenberg-functions.php.
You can test in any theme running Wordpress 6.1, such as Tool.
We currently have these two functions in an attempt to auto load the default ACF fields:
https://github.com/funkhaus/fuxt-backend/blob/master/functions/acf-functions.php#L2-L21
But it doesn't seem to work.
Ideally on theme activation, the default ACF fields from here get loaded into ACF.
We don't need them to get saved into the theme like it does now, we can use Flywheel backups on the rare occasion we need a record of past ACF fields.
It would be really useful to have an ACF location rule that allowed us to add a field group to a page that has NO children (or the opposite, only pages that have children)
If you go to /wp-login and login with the right details, it redirects you back to the /wp-login page. Then you have to go to /wp-admin to get to the dashboard. I suspect this is related to the new cookie things built into the site.
I've also noticed that when you logout, it asks you to confirm that you want to log out... never seen that before.
We need a custom gutenberg block that builds a gallery, but one that shows a single row of images and has scrollbars to move it.
It's important the interface for this looks like a native WordPress block.
On the frontend, we will style it to look like this (You do not have to build frontend Vue component):
So the idea is a long row of images, that are sized 70vw and height auto, and then a "overflow-x: auto" container. Our frontend component will then have a "click and drag" style scroll in place on desktop, or swipe to scroll on mobile. We will use this: https://components.funkhaus.us/?path=/story/ui-scrollers-drag--default
I tried getting this working with ACF Blocks here: https://github.com/funkhaus/fuxt-backend/tree/master/blocks
But it didn't work in WP-GQL-Gutenberg and also the interface looks a little ad-hock. This native block request will replace this block.
#import "~/gql/fragments/GutenbergBlocks.gql"
query NewsDetail($uri: String!) {
nodeByUri(uri: $uri) {
id
... on Post {
title
...GutenbergBlocks # This will mean the nextPost and prevPost will not work!
previousPost {
node {
id
uri
title
}
}
nextPost {
node {
id
uri
title
}
}
...GutenbergBlocks # This will mean the nextPost and prevPost work
}
}
}
Very possible this is an issue with https://github.com/funkhaus/wp-gql-gutenberg
It looks like they changed the format for the ORDER where clauses.
It used to be this:
https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php#L532-L533
But now it needs to be like this:
children(
where: {
orderby: { field: MENU_ORDER, order: ASC }
}
) {
When using Gutennberg editor, the console logs a lot of errors:
I tracked it down to this function: https://github.com/funkhaus/fuxt-backend/blob/master/functions/wp-functions.php#L280-L284
So now the question is, how to fix it? It seems weird that Gutenberg is doing API requests to the home URL, not the actual WordPress install URLs.
The whole point of that code was to get preview URL's linking out to the frontend correctly. So perhaps it's OK to just do a check for "is REST request" and if so, return the correct default home URL?
We want a gutenberg block that is an 70vh background image, with SVG logos overlaid in front of it.
It's important this block feel like a native WordPress block.
We are going to use it like this on the frontend:
The each logo will be displayed in a 200px tall, auto width box always. Vertically and horizontally centered, and allowed to wrap onto new lines if enough logos uploaded.
Mostly the logos will be SVGs, but could also be PNGs or JPGs.
I think this is an issue with WordPress in general, but ideally the Gutenberg preview link respects the filters defined here: https://github.com/funkhaus/fuxt-backend/blob/master/functions/wp-functions.php#L171
Would be great if we could do this:
query MyQuery {
mediaItems {
nodes {
sourceUrl
... on Svg {
content
}
}
}
}
And content
gives us the contents of the SVG that was uploaded <svg>...</svg>
. Alternatively that could be called markup
or xml
if content
conflicts with the other content field name.
It should be added to this file: https://github.com/funkhaus/fuxt-backend/blob/master/functions/gql-functions.php
wp-graphql/wp-graphql#261 (comment)
Probably should just change the default to 50, anything beyond that should use lazy loading.
The "is tree" rule works on it's own, but when combined with "Page parent NOT equal too" it doesn't work.
This is the custom "is tree" rule.
https://github.com/funkhaus/fuxt-backend/blob/master/functions/acf-functions.php#L48-L55
A common use case for this is when we only want a field group to show up on deeper child pages, like:
Having a field group only show up on "Person name".
Alternatively it would also be good to have a "No children" location ACF filter.
Password reset emails (and any email from wordpress) get blocked, partly because WordPress is sending them with the "from" address being the frontend domain, which isn't actually the server sending them, it should be the backend domain.
So we should filter the default from address to be the backend domain.
When we clone a site to staging, the cookie logic seems to break the ability to login. I have to disable the theme via FTP, then login and re enable the theme.
Currently the ACF plugin allows you to create a custom taxonimes and post types through the UI.
But it doesn't yet allow you to enable those in WP-GQL. I know it's planned to allow this, but in the meantime I'd like to auto enable all the ones that are made by ACF that also have show in rest API enabled
(see screenshot).
For example, here is the code that allows you to set a pre-made taxonomy to show in GQL:
add_filter( 'register_taxonomy_args', function( $args, $taxonomy ) {
if ( 'doc_tag' === $taxonomy ) {
$args['show_in_graphql'] = true;
$args['graphql_single_name'] = 'documentTag';
$args['graphql_plural_name'] = 'documentTags';
}
return $args;
}, 10, 2 );
So it would just be a matter of making that work for custom post types too, and to do some test for show_in_rest
to be true also.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.