rankmath testing

This commit is contained in:
Antoine M 2024-07-04 10:25:00 +02:00
parent e524958c99
commit 7fa25fa3a8
10 changed files with 85 additions and 51 deletions

View File

@ -24,6 +24,10 @@
"relatedPostId": {
"type": "number"
},
"relatedPostPreviewGhostContent": {
"type": "string",
"default": ""
},
"postType": {
"type": "string",
"default": "questions"

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => '548c237f02dcdec27f46');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-html-entities', 'wp-i18n'), 'version' => 'f8adefcd282fd42751be');

View File

@ -174,8 +174,25 @@ function Edit({
}) {
const {
relatedPostId,
postType
postType,
relatedPostPreviewGhostContent
} = attributes;
let currentRelatedPost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => relatedPostId && postType ? select("core").getEntityRecord("postType", postType, relatedPostId) : null, [relatedPostId, postType]);
// console.log("relatedPostPreviewGhostContent", relatedPostPreviewGhostContent);
// useEffect(() => {
// if (currentRelatedPost?.content?.rendered) {
// setAttributes({
// relatedPostPreviewGhostContent: currentRelatedPost.content.rendered,
// });
// } else {
// setAttributes({
// relatedPostPreviewGhostContent: null,
// });
// }
// }, [currentRelatedPost]);
function parseBlockContentForTooltips(editorContent) {
const parser = new DOMParser();
const doc = parser.parseFromString(editorContent, "text/html");
@ -198,7 +215,6 @@ function Edit({
});
return filteredTooltipWords;
}
let currentRelatedPost = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.useSelect)(select => relatedPostId && postType ? select("core").getEntityRecord("postType", postType, relatedPostId) : null, [relatedPostId, postType]);
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_5__.useEffect)(() => {
if (currentRelatedPost) {
const currentBlockTooltips = parseBlockContentForTooltips(currentRelatedPost.content.rendered);
@ -260,7 +276,7 @@ __webpack_require__.r(__webpack_exports__);
foreground: "#DF1E1E"
},
edit: _edit__WEBPACK_IMPORTED_MODULE_3__["default"],
save: _save__WEBPACK_IMPORTED_MODULE_4__["default"],
// save,
transforms: _transforms__WEBPACK_IMPORTED_MODULE_6__["default"]
});
@ -289,7 +305,11 @@ function save({
attributes,
setAttributes
}) {
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, "Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dignissimos reiciendis officiis molestias nostrum necessitatibus, explicabo culpa assumenda quod sit facere. Ullam vitae dignissimos quasi ea amet nisi rerum omnis saepe!"));
const {
relatedPostPreviewGhostContent
} = attributes;
if (!relatedPostPreviewGhostContent) return null;
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, relatedPostPreviewGhostContent);
}
/***/ }),
@ -444,7 +464,7 @@ module.exports = window["wp"]["i18n"];
\************************/
/***/ ((module) => {
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/post-content-container","version":"0.1.0","title":"Post Container","category":"homegrade-blocks","icon":{"background":"#fff","foreground":"#DF1E1E","src":"feedback"},"description":"Pour intégrer le contenu d\'une page ou d\'un post type","supports":{"anchor":true,"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"relatedPostId":{"type":"number"},"postType":{"type":"string","default":"questions"},"anchor":{"type":"string"},"tooltipsWordsUsed":{"type":"array","default":[]}}}');
module.exports = /*#__PURE__*/JSON.parse('{"$schema":"https://schemas.wp.org/trunk/block.json","apiVersion":2,"name":"homegrade-content-blocks/post-content-container","version":"0.1.0","title":"Post Container","category":"homegrade-blocks","icon":{"background":"#fff","foreground":"#DF1E1E","src":"feedback"},"description":"Pour intégrer le contenu d\'une page ou d\'un post type","supports":{"anchor":true,"html":false},"textdomain":"homegrade-theme__bloks-texte-fonctionnel","editorScript":"file:./index.js","editorStyle":"file:./index.css","style":"file:./style-index.css","render":"file:./render.php","attributes":{"relatedPostId":{"type":"number"},"relatedPostPreviewGhostContent":{"type":"string","default":""},"postType":{"type":"string","default":"questions"},"anchor":{"type":"string"},"tooltipsWordsUsed":{"type":"array","default":[]}}}');
/***/ })

File diff suppressed because one or more lines are too long

View File

@ -9,22 +9,21 @@ $anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_ht
$anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_html($attributes['anchor']) : ($relatedPostId ? "post-content-container-" . $relatedPostId : '');
$content = get_the_content(null, null, $relatedPost);
// if ($relatedPost) {
// // Temporarily set up the global post variable so the_content works as expected
// global $post;
// $post = $relatedPost;
// setup_postdata($post);
if ($relatedPost) {
// Temporarily set up the global post variable so the_content works as expected
global $post;
$post = $relatedPost;
setup_postdata($post);
// ob_start();
// the_content();
// $content = ob_get_clean();
// wp_reset_postdata();
// }
ob_start();
the_content();
$content = ob_get_clean();
wp_reset_postdata();
}
?>
<section id="<?php echo $anchor ?>" class="post-content-container <?php echo $anchor ? "has-custom-anchor" : "" ?>">
<h2 class="post-content-container__title"><?php echo $relatedPost->post_title ?></h2>
<!-- <?php echo $content; ?> -->
<?php echo $relatedPost->post_content ?>
<?php echo $content; ?>
</section>

View File

@ -24,6 +24,10 @@
"relatedPostId": {
"type": "number"
},
"relatedPostPreviewGhostContent": {
"type": "string",
"default": ""
},
"postType": {
"type": "string",
"default": "questions"

View File

@ -9,7 +9,29 @@ import { decodeEntities } from "@wordpress/html-entities";
import OptionsSelectControl from "./OptionsSelectControl";
export default function Edit({ attributes, setAttributes }) {
const { relatedPostId, postType } = attributes;
const { relatedPostId, postType, relatedPostPreviewGhostContent } =
attributes;
let currentRelatedPost = useSelect(
(select) =>
relatedPostId && postType
? select("core").getEntityRecord("postType", postType, relatedPostId)
: null,
[relatedPostId, postType],
);
// console.log("relatedPostPreviewGhostContent", relatedPostPreviewGhostContent);
// useEffect(() => {
// if (currentRelatedPost?.content?.rendered) {
// setAttributes({
// relatedPostPreviewGhostContent: currentRelatedPost.content.rendered,
// });
// } else {
// setAttributes({
// relatedPostPreviewGhostContent: null,
// });
// }
// }, [currentRelatedPost]);
function parseBlockContentForTooltips(editorContent) {
const parser = new DOMParser();
@ -41,14 +63,6 @@ export default function Edit({ attributes, setAttributes }) {
return filteredTooltipWords;
}
let currentRelatedPost = useSelect(
(select) =>
relatedPostId && postType
? select("core").getEntityRecord("postType", postType, relatedPostId)
: null,
[relatedPostId, postType],
);
useEffect(() => {
if (currentRelatedPost) {
const currentBlockTooltips = parseBlockContentForTooltips(

View File

@ -28,6 +28,6 @@ registerBlockType(metadata.name, {
},
edit: Edit,
save,
// save,
transforms: transforms,
});

View File

@ -9,22 +9,21 @@ $anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_ht
$anchor = isset($attributes['anchor']) && !empty($attributes['anchor']) ? esc_html($attributes['anchor']) : ($relatedPostId ? "post-content-container-" . $relatedPostId : '');
$content = get_the_content(null, null, $relatedPost);
// if ($relatedPost) {
// // Temporarily set up the global post variable so the_content works as expected
// global $post;
// $post = $relatedPost;
// setup_postdata($post);
if ($relatedPost) {
// Temporarily set up the global post variable so the_content works as expected
global $post;
$post = $relatedPost;
setup_postdata($post);
// ob_start();
// the_content();
// $content = ob_get_clean();
// wp_reset_postdata();
// }
ob_start();
the_content();
$content = ob_get_clean();
wp_reset_postdata();
}
?>
<section id="<?php echo $anchor ?>" class="post-content-container <?php echo $anchor ? "has-custom-anchor" : "" ?>">
<h2 class="post-content-container__title"><?php echo $relatedPost->post_title ?></h2>
<!-- <?php echo $content; ?> -->
<?php echo $relatedPost->post_content ?>
<?php echo $content; ?>
</section>

View File

@ -2,14 +2,8 @@ import { useBlockProps, RichText, InnerBlocks } from "@wordpress/block-editor";
import { __ } from "@wordpress/i18n";
export default function save({ attributes, setAttributes }) {
return (
<>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dignissimos
reiciendis officiis molestias nostrum necessitatibus, explicabo culpa
assumenda quod sit facere. Ullam vitae dignissimos quasi ea amet nisi
rerum omnis saepe!
</p>
</>
);
const { relatedPostPreviewGhostContent } = attributes;
if (!relatedPostPreviewGhostContent) return null;
return <>{relatedPostPreviewGhostContent}</>;
}