How to fetch 'theme' from the below $themes map?
$themes: (
default: (
theme: blue,
)
);
I tried with the below map with single child and it works with map-get()
SCSS
$default: (
theme: red,
);
#function fetchColor($issuer, $key) {
#return map-get($issuer, $key);
}
.navbar-brand {
background : fetchColor($default, theme);
}
Result
.navbar-brand {
background: red;
}
How to fetch the same from '$themes' map?
You can use a solution as described by css-tricks.com:
$themes: (
default: (
theme: blue,
)
);
#function fetchColor($map, $keys...) {
#each $key in $keys {
$map: map-get($map, $key);
}
#return $map;
}
.navbar-brand {
background: fetchColor($themes, default, theme);
}
Related
How can I pass a list of functions as the value of a mapping in SCSS and then run those functions?
This is what I have
$mappings: (
'x':(func1('1', '2'), func2('1', '2', '3'))
);
#include apply-mappings($mappings);
// In my mixin file
#mixin apply-mappings($mappings) {
#each $key, $value in $mappings {
#if type-of($value) == 'list' {
#each $item in $value {
// Run $item which is a function
}
}
}
}
#mixin/function func1($item1, $item2) {
// Do something
}
#mixin/function func2($item1, $item2, $item3) {
// Do something else
}
I get Uncaught TypeError: Cannot read properties of undefined (reading 'elements') error and can't see my wheel and plane with a shadow texture on the floor:
Here's my code:
const loader = new FBXLoader();
#foreach ($files as $file)
#if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) == 'fbx')
loader.setResourcePath('storage/models/{{ $modelId }}/').load('storage/{{ $file }}', function ( object ) {
object.traverse( function ( child ) {
if ( child.isMesh ) {
if ( child instanceof THREE.Mesh ) {
// child.material.color.setRGB (1, 0, 0);
child.material = new THREE.MeshPhongMaterial( {
color: 0xffffff,
map: child.material.map
} );
}
}
} );
object.receiveShadow = true;
object.castShadow = true;
scene.add( object );
} );
#endif
#endforeach
here's how this car should looks like:
I do not understand how to display a notice after a term creation in WordPress.
I have a custom field in a custom taxonomy. On the save event, I check if the value is incorrect and in this case, I want to display a notice.
I have a similar situation in the post editor but here I have solved with add_settings_error and admin_notices.
This method does not work in the term creation screen because in this scenario, there is an AJAX request and the page does not reload.
Here is the code about term screen:
add_action('create_account', 'save_start_amount_data__fr');
add_action('admin_notices', 'display_start_amount_data_validation_error__fr');
function save_start_amount_data__fr($term_id) {
if (
!isset($_POST['start_amount_nonce']) ||
!wp_verify_nonce($_POST['start_amount_nonce'], 'start_amount_nonce')
) {return $term_id;}
if (
(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
) {return $term_id;}
if (
!isset($_POST['taxonomy']) ||
$_POST['taxonomy'] != 'account' ||
!current_user_can('edit_posts')
) {return $term_id;}
if (
!isset($_POST['start_amount'])
) {return $term_id;}
if (
!preg_match('/^[-]?[0-9]+([,]?[0-9]{1,2})?$/', $_POST['start_amount'])
) {validate_start_amount_data__fr();}
$start_amount = $_POST['start_amount'];
$start_amount = sanitize_text_field($start_amount);
update_term_meta($term_id, 'start_amount', $start_amount);
return $term_id;
}
function validate_start_amount_data__fr() {
add_settings_error(
'incorrect_start_amount_value',
'incorrect_start_amount_value',
__('Please review the start amount value because it is in an incorrect format.', 'fr'),
'error'
);
set_transient('settings_errors', get_settings_errors(), 30);
return null;
}
function display_start_amount_data_validation_error__fr() {
$errors = get_transient('settings_errors');
if (!$errors) {return null;}
$message = '<div class="notice notice-error"><ul>';
foreach($errors as $error) {
$message .= '<li>' . $error['message'] . '</li>';
}
$message .= '</ul></div>';
echo $message;
delete_transient('settings_errors');
remove_action('admin_notices', 'display_start_amount_data_validation_error__fr');
return null;
}
I hope that someone can help me to achieve my goal.
See below the method that I'm using on a Custom Posts to display notifications.
Take a look to the filter "redirect_post_location".
//Actions
$this->loader->add_action( 'admin_notices', $plugin_admin, 'general_admin_notice' );
$this->loader->add_action( 'save_post', $plugin_admin, 'admin_save_post' );
/**
* Admin Save the Meta box values
*
* #since 1.0.0
*/
function admin_save_post( $id ) {
/* --- security verification --- */
if(!wp_verify_nonce($_POST['attachment_nonce'], plugin_basename(__FILE__))) {
return $id;
} // end if
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $id;
} // end if
if('page' == $_POST['post_type']) {
if(!current_user_can('edit_page', $id)) {
return $id;
} // end if
} else {
if(!current_user_can('edit_page', $id)) {
return $id;
} // end if
} // end if
/* - end security verification - */
// Make sure the file array isn't empty
if(!empty($_FILES['secure_doc_attachment']['name'])) {
$upload = $this->admin_upload_file( $_FILES , $id );
if (!$upload){
add_filter('redirect_post_location', function($loc) {
return add_query_arg( 'error', 1, $loc );
});
return $post_id;
}
}
}
/**
* Admin Notice
*
* #since 1.0.0
*/
function general_admin_notice(){
global $pagenow;
if ( 'post.php' === $pagenow && isset($_GET['post']) && 'custom-post' === get_post_type( $_GET['post'] ) ){
if ( isset($_GET['error'])) {
echo '<div class="notice notice-error is-dismissible">
<p>Error uploading the attachment.</p>
</div>';
}
}
}
See other useful link here:
https://wordpress.stackexchange.com/questions/124132/admin-post-update-redirection-to-posts-screen
Regards.
Ed.
how to show product randomly in woo-commerce slider. now I use this code in function.php and some of my page work random but slider not working.
this is webpage : fidarabzar.ir
[fusion_products_slider picture_size="auto" cat_slug="مته" number_posts="30" carousel_layout="title_on_rollover" autoplay="yes" columns="5" column_spacing="" scroll_items="" show_nav="yes" mouse_scroll="no" show_cats="yes"show_price="yes" show_buttons="yes" hide_on_mobile="small-visibility,medium-visibility,large-visibility" class="" id=""][/fusion_products_slider ]
php code
add_filter( 'woocommerce_get_catalog_ordering_args',
'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
$orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean(
$_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby',
get_option( 'woocommerce_default_catalog_orderby' ) );
if ( 'random_list' == $orderby_value ) {
$args['orderby'] = 'rand';
$args['order'] = '';
$args['meta_key'] = '';
}
return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options',
'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby',
'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
$sortby['random_list'] = 'Random';
return $sortby;
}
I know can get value in 1D map with map-get() function but dont know how get value like 'header' in this map:
$mobile-layout: (
layout-values: (
header: (
height: 72px
),
sidebar: (
width: 100%
)
)
);
I have a couple nested loop solutions...
DEMO
3 loops
#each $key, $val in $mobile-layout {
#each $k, $v in $val {
#each $l, $t in $v {
.#{$k} {
.#{$l}: #{$t};
}
}
}
}
2 loops
#each $key, $val in $mobile-layout {
#each $k, $v in $val {
.#{$k} {
.#{map-keys($v)}: #{map-values($v)};
}
}
}