diff --git a/assets/editor-min.js b/assets/editor-min.js index b1d5103..df19a0a 100644 --- a/assets/editor-min.js +++ b/assets/editor-min.js @@ -1 +1 @@ -function eqdReorderBlockCategories(e){const{getCategories:o,setCategories:l}=wp.blocks,r=o().find((o=>o.slug===e)),t=o().filter((o=>o.slug!==e));r&&l([r,...t])}wp.domReady((()=>{wp.blocks.unregisterBlockStyle("core/button",["default","outline","squared","fill"]),wp.blocks.registerBlockStyle("core/button",[{name:"default",label:"Default",isDefault:!0},{name:"outline",label:"Outline"},{name:"arrow",label:"Arrow"}]),wp.blocks.unregisterBlockStyle("core/separator",["default","wide","dots"]),wp.blocks.unregisterBlockStyle("core/quote",["default","large"]),wp.blocks.unregisterBlockType("core/media-text"),wp.blocks.unregisterBlockType("core/search")})),wp.hooks.addFilter("blocks.registerBlockType","be/groupAlignments",(function(e,o){return"core/group"===o?lodash.assign({},e,{supports:lodash.assign({},e.supports,{align:["wide","full","center"]})}):e})),eqdReorderBlockCategories("custom-blocks"); \ No newline at end of file +function eqdReorderBlockCategories(e){const{getCategories:t,setCategories:o}=wp.blocks,l=t().find((t=>t.slug===e)),s=t().filter((t=>t.slug!==e));l&&o([l,...s])}wp.domReady((()=>{wp.blocks.unregisterBlockStyle("core/button",["default","outline","squared","fill"]),wp.blocks.registerBlockStyle("core/button",[{name:"default",label:"Default",isDefault:!0},{name:"outline",label:"Outline"},{name:"arrow",label:"Arrow"}]),wp.blocks.unregisterBlockStyle("core/separator",["default","wide","dots"]),wp.blocks.unregisterBlockStyle("core/quote",["default","large"]),wp.blocks.unregisterBlockType("core/media-text"),wp.blocks.unregisterBlockType("core/search")})),wp.hooks.addFilter("blocks.registerBlockType","be/groupAlignments",(function(e,t){return"core/group"===t?lodash.assign({},e,{supports:lodash.assign({},e.supports,{align:["wide","full","center"]})}):e})),eqdReorderBlockCategories("custom-blocks"),document.addEventListener("mouseover",(function(e){const t=document.querySelector(".block-editor-inserter__preview-content-missing");if(t&&e.target.closest(".block-editor-block-types-list__item")){const o=undefined,l=undefined,s=e.target.closest(".block-editor-block-types-list__item").className.split(" ").find((e=>e.startsWith("editor-block-list-item-acf-")));if(s){const e=s.replace("editor-block-list-item-acf-",""),o=wp.data.select("core/blocks").getBlockType("acf/"+e)?.attributes?.previewImage?.default;o?(t.style.background=`url(${o}) no-repeat center`,t.style.backgroundSize="contain",t.style.fontSize="0px"):(t.style.background="",t.style.backgroundSize="",t.style.fontSize="")}}})); \ No newline at end of file diff --git a/assets/js/editor.js b/assets/js/editor.js index aa58f6a..09d005e 100644 --- a/assets/js/editor.js +++ b/assets/js/editor.js @@ -76,3 +76,49 @@ function eqdReorderBlockCategories(customSlug) { // Example usage: prioritize the 'custom-blocks' category eqdReorderBlockCategories('custom-blocks'); +/** + * Event listener to dynamically update the background image of a preview container + * in the block editor based on the mouseover event on block items. + * + * This provides a dynamic preview mechanism in the block editor based on the block the user is hovering over. + */ +document.addEventListener("mouseover", function(e) { + // Selector to preview block where you want to show background image. + const previewContainer = document.querySelector('.block-editor-inserter__preview-content-missing'); + + if (!previewContainer) { + return; + } + + if (e.target.closest('.block-editor-block-types-list__item')) { + const hoveredBlock = e.target.closest('.block-editor-block-types-list__item'); + + // to find a name of the block we can extract it from block classes. + + // Retrieve classes from the block on which the mouse is hovered. + const blockClasses = hoveredBlock.className.split(' '); + + // Finding a class that starts with "editor-block-list-item-acf-". + const blockClass = blockClasses.find( cls => cls.startsWith("editor-block-list-item-acf-" ) ); + + // If such a class is found, extract the name from it. + if ( blockClass ) { + const blockName = blockClass.replace( "editor-block-list-item-acf-", "" ); + + // Get the image URL for this block + const imageUrl = wp.data.select( 'core/blocks' ).getBlockType( "acf/" + blockName )?.attributes?.previewImage?.default; + + // adding our styles if there is a link to the picture. + if ( imageUrl ) { + previewContainer.style.background = `url(${imageUrl}) no-repeat center`; + previewContainer.style.backgroundSize = 'contain'; + previewContainer.style.fontSize = '0px'; + } else { + // remove our styles if there is no link. + previewContainer.style.background = ''; + previewContainer.style.backgroundSize = ''; + previewContainer.style.fontSize = ''; + } + } + } +}); diff --git a/config.codekit3 b/config.codekit3 index a23be90..18c954c 100644 --- a/config.codekit3 +++ b/config.codekit3 @@ -3720,6 +3720,19 @@ "oO" : 0, "oS" : 1 }, + "\/template-parts\/blocks\/accordion\/screenshot.png" : { + "ft" : 32768, + "iS" : 7422, + "oA" : 0, + "oAP" : "\/template-parts\/blocks\/accordion\/screenshot.png", + "oF" : 0, + "oIPL" : 0, + "opt" : 0, + "oT" : 1, + "ou" : "lpckwebp-none", + "q" : 100, + "rq" : 75 + }, "\/template-parts\/blocks\/accordion\/template.php" : { "cB" : 0, "ft" : 8192, @@ -3736,6 +3749,19 @@ "oO" : 0, "oS" : 1 }, + "\/template-parts\/blocks\/calculator-form-cta\/screenshot.png" : { + "ft" : 32768, + "iS" : 10000, + "oA" : 0, + "oAP" : "\/template-parts\/blocks\/calculator-form-cta\/screenshot.png", + "oF" : 0, + "oIPL" : 0, + "opt" : 0, + "oT" : 1, + "ou" : "lpckwebp-none", + "q" : 100, + "rq" : 75 + }, "\/template-parts\/blocks\/calculator-form-cta\/template.php" : { "cB" : 0, "ft" : 8192, diff --git a/functions.php b/functions.php index 1ba342b..1bceaf5 100644 --- a/functions.php +++ b/functions.php @@ -296,17 +296,17 @@ function eqd_template_hierarchy( $template ) { * * @return array The modified query arguments. */ -function custom_acf_post_object_query( $args, $field, $post_id ) { +function npp_custom_acf_post_object_query( $args, $field, $post_id ) { // Check if the field being queried is named 'recommended_posts'. - if ($field['name'] === 'recommended_posts') { + if ( $field['name'] === 'recommended_posts' ) { // Modify the query to search for post titles only. $args['post_type'] = 'post'; - $args['s'] = ''; // Clear any previous search query. + //$args['s'] = ''; // Clear any previous search query. $args['search_columns'] = array('post_title'); } return $args; } -add_filter('acf/fields/post_object/query', 'custom_acf_post_object_query', 10, 3); +add_filter( 'acf/fields/post_object/query', 'npp_custom_acf_post_object_query', 10, 3 ); /** * Filters the query arguments for the 'recommendedfeatured_posts' ACF Post Object field. @@ -345,3 +345,31 @@ function npp_filter_post_object_query( $args, $field, $post_id ) { return $args; } add_filter( 'acf/fields/post_object/query', 'npp_filter_post_object_query', 10, 3 ); + +function modify_post_object_query( $args, $field, $post_id ) { + // Check if the parent block is 'acf/recommended-posts-block' + if ( isset($field['parent']) && $field['parent'] == 'block_acf/recommended-posts-block' ) { + // If there's a search term, modify the query to search by title only + if( isset($args['s']) ) { + // Set search term to a variable + $search_term = $args['s']; + + // Modify the query + unset($args['s']); // Remove default search + $args['post_title_like'] = $search_term; // Add title search + } + } + + // Return the modified arguments + return $args; +} +add_filter('acf/fields/post_object/query', 'modify_post_object_query', 10, 3); + +function title_like_posts_where( $where, $wp_query ) { + global $wpdb; + if ( $post_title_like = $wp_query->get('post_title_like') ) { + $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( $wpdb->esc_like( $post_title_like ) ) . '%\''; + } + return $where; +} +add_filter('posts_where', 'title_like_posts_where', 10, 2); diff --git a/template-parts/blocks/accordion/block.json b/template-parts/blocks/accordion/block.json index 38db9fe..497e913 100644 --- a/template-parts/blocks/accordion/block.json +++ b/template-parts/blocks/accordion/block.json @@ -13,5 +13,11 @@ "acf": { "mode": "preview", "renderTemplate": "template.php" + }, + "attributes": { + "previewImage": { + "type": "string", + "default": "/wp-content/themes/student-loan-planner-theme/template-parts/blocks/accordion/screenshot.png" + } } } \ No newline at end of file diff --git a/template-parts/blocks/accordion/screenshot.png b/template-parts/blocks/accordion/screenshot.png new file mode 100644 index 0000000..74ce150 Binary files /dev/null and b/template-parts/blocks/accordion/screenshot.png differ diff --git a/template-parts/blocks/calculator-form-cta/block.json b/template-parts/blocks/calculator-form-cta/block.json index c5c02af..f09f498 100644 --- a/template-parts/blocks/calculator-form-cta/block.json +++ b/template-parts/blocks/calculator-form-cta/block.json @@ -12,5 +12,11 @@ "acf": { "mode": "preview", "renderTemplate": "template.php" + }, + "attributes": { + "previewImage": { + "type": "string", + "default": "/wp-content/themes/student-loan-planner-theme/template-parts/blocks/calculator-form-cta/screenshot.png" + } } } \ No newline at end of file diff --git a/template-parts/blocks/calculator-form-cta/screenshot.png b/template-parts/blocks/calculator-form-cta/screenshot.png new file mode 100644 index 0000000..78f5d1f Binary files /dev/null and b/template-parts/blocks/calculator-form-cta/screenshot.png differ