0

While digging recently on how to find site url from block editor, I found this article, where I found my answer, as site url is a property of object getSite returns.

Now, I searched through the Gutenberg code (trunk version from github) to find definition of getSite selector, but I was unable to find it's definition.

Can someone point me to definition of this selector in code, I want to inspect code a little better to see what paramater (if any) does it take?

P.S. most of the selectors in 'core' store are defined in gutenberg/packages/core-data/src/selectors.ts, but this is not, yet, it is present in the store.

1 Answer 1

2

I found it - it is dynamically injected as entity in gutenberg/packages/core-data/src/index.js, on line 22

const entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {
    const { kind, name } = entity;
    result[ getMethodName( kind, name ) ] = ( state, key, query ) =>
        selectors.getEntityRecord( state, kind, name, key, query );
    result[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>
        selectors.getEntityRecords( state, kind, name, query );
    return result;
}, {} );

While entities are defined in gutenberg/packages/core-data/src/entities.js, it is this entity:

    {
        label: __( 'Site' ),
        name: 'site',
        kind: 'root',
        baseURL: '/wp/v2/settings',
        getTitle: ( record ) => {
            return get( record, [ 'title' ], __( 'Site Title' ) );
        },
    },

EDIT: getSite does not take any parameters and it returns object with following properties:

0: "title"​
1: "description"​
2: "url"​
3: "email"​
4: "timezone"​
5: "date_format"​
6: "time_format"​
7: "start_of_week"​
8: "language"​
9: "use_smilies"
10: "default_category"​
11: "default_post_format"​
12: "posts_per_page"​
13: "show_on_front"​
14: "page_on_front"​
15: "page_for_posts"​
16: "default_ping_status"​
17: "default_comment_status"​
18: "site_logo"​
19: "site_icon"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.