You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I remove the add_meta_box from class-metabox.php, I'm left with sidebar, however, I do need to find a away to add the hidden fields since the sidebar is using them. This is done in the method render_hidden_fields. render_hidden_fields is rendering the hidden fields of a form that is submitted once the post is updated.
In the metabox class it is rendered as part of the metabox and the sidebar is depending on those fields to get data relating to:
SEO analysis
Readability analysis
Inclusive language analysis
Those fields are also simultaneously updated when settings are changed in the metabox or sidebar.
This separation is also done in elementor.php. The render_hidden_fields is rendering a complete form while the metabox render_hidden_fields is rendering only the input fields.
Without the metabox, the hidden fields are not needed. Once the metabox is removed, the data should be from the used fields not the hidden fields. Better to use redux store and not hidden fields.
The ideal solution would be to get the data from the store (get the initial data from localised script) and update the data in the store ( That is done here: wordpress-seo/packages/js/src/helpers/fields/AnalysisFields.js). From the store it should be accessible to the metabox, sidebar and form.
This change might require the changing Meta_Fields_Presenter since it returns the html input fields while will need to construct them on the JS side.
Using this guide:
The meta fields can be registered like so:
Tried to implement this for focus keyphrase, was able to add it to the store but it won't save. (based on this example).
Was able to fix it by adding shoe_in_rest => true when registering the meta in WPSEO_Meta init method.
JS side is separated with different slots and fills according to location from a LocationProvider.
global $post does not work on site editor and neither other WP methods related to current post.
The redux store core/edit-site include editedPost.context where we can get post id, and post type
post-edit.js Register the store for the usage of the block editor and the metabox, however it also initialise the tabs for the metabox. Either that should be separated or conditioned.
Files to change when moving away from hidden fields:
packages/yoastseo/src/app.js on App.prototype.bindInputEvent which adds event listener to the hidden fields.
packages/js/src/initializer/post-scraper.js in initializePostAnalysis for signing value to hidden fields: $( "#yoast_wpseo_focuskw" ).val( focusKeyword );
packages/js/src/analysis/PostDataCollector.js under PostDataCollector.prototype.getKeyword
packages/js/src/helpers/fields/AnalysisFields.js under static get keyphraseElement
The hidden fields method should be preserved in case user is using the classic editor. In that casr the store is not available.
I recommend assigning the initial state and updating the data according to 3 different states:
Classic editor (hidden fields) (only for metabox)
Block editor ( core/editor store ) ( for both metabox and sidebar)
Site editor ( core store) (only for sidebar)
I added the hidden fields values to wpseoScriptData.
I added a JS class to fetch initial value for hidden fields from wpseoScriptData and update according to the editor (PostMeta.js).
The following task list is for all the actions that need to be updated, and the classes that are used now and should be removed:
The content you are editing has changed. Please copy your edits and refresh the page.
Hidden fields to treat and - classes and path (packages/js/src)
If I remove the
add_meta_box
fromclass-metabox.php
, I'm left with sidebar, however, I do need to find a away to add the hidden fields since the sidebar is using them. This is done in the methodrender_hidden_fields
.render_hidden_fields
is rendering the hidden fields of a form that is submitted once the post is updated.In the metabox class it is rendered as part of the metabox and the sidebar is depending on those fields to get data relating to:
Those fields are also simultaneously updated when settings are changed in the metabox or sidebar.
This separation is also done in
elementor.php
. Therender_hidden_fields
is rendering a complete form while the metaboxrender_hidden_fields
is rendering only the input fields.Without the metabox, the hidden fields are not needed. Once the metabox is removed, the data should be from the used fields not the hidden fields. Better to use redux store and not hidden fields.
The ideal solution would be to get the data from the store (get the initial data from localised script) and update the data in the store ( That is done here:
wordpress-seo/packages/js/src/helpers/fields/AnalysisFields.js
). From the store it should be accessible to the metabox, sidebar and form.This change might require the changing
Meta_Fields_Presenter
since it returns the html input fields while will need to construct them on the JS side.Using this guide:
The meta fields can be registered like so:
And then they will appear under meta in the
core/editor
store:Another way to retrieve and update this meta with
useEntityProp
from :Tried to implement this for focus keyphrase, was able to add it to the store but it won't save. (based on this example).
Was able to fix it by adding
shoe_in_rest => true
when registering the meta inWPSEO_Meta
init method.JS side is separated with different slots and fills according to location from a
LocationProvider
.global $post
does not work on site editor and neither other WP methods related to current post.core/edit-site
includeeditedPost.context
where we can get post id, and post typepost-edit.js
Register the store for the usage of the block editor and the metabox, however it also initialise the tabs for the metabox. Either that should be separated or conditioned.Files to change when moving away from hidden fields:
packages/yoastseo/src/app.js
onApp.prototype.bindInputEvent
which adds event listener to the hidden fields.packages/js/src/initializer/post-scraper.js
ininitializePostAnalysis
for signing value to hidden fields:$( "#yoast_wpseo_focuskw" ).val( focusKeyword );
packages/js/src/analysis/PostDataCollector.js
underPostDataCollector.prototype.getKeyword
packages/js/src/components/contentAnalysis/KeywordInputComponent.js
packages/js/src/helpers/fields/AnalysisFields.js
understatic get keyphraseElement
The hidden fields method should be preserved in case user is using the classic editor. In that casr the store is not available.
I recommend assigning the initial state and updating the data according to 3 different states:
core/editor
store ) ( for both metabox and sidebar)core
store) (only for sidebar)I added the hidden fields values to
wpseoScriptData
.I added a JS class to fetch initial value for hidden fields from
wpseoScriptData
and update according to the editor (PostMeta.js
).The following task list is for all the actions that need to be updated, and the classes that are used now and should be removed:
Hidden fields to treat and - classes and path (packages/js/src)
Tasks
The text was updated successfully, but these errors were encountered: