Skip to content

Commit

Permalink
Merge branch 'stage' into feature/local-dev-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tronsymphony committed Nov 9, 2023
2 parents 598f184 + 75a68ec commit e15bb7a
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 5 deletions.
2 changes: 1 addition & 1 deletion assets/editor-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
}
}
});
26 changes: 26 additions & 0 deletions config.codekit3
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
36 changes: 32 additions & 4 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
6 changes: 6 additions & 0 deletions template-parts/blocks/accordion/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Binary file added template-parts/blocks/accordion/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions template-parts/blocks/calculator-form-cta/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e15bb7a

Please sign in to comment.