function display_exif_fields ( $form_fields, $post ){
$type = get_post_mime_type( $post->ID );
$attachment_path = get_attached_file( $post->ID );
$metadata = wp_read_image_metadata_exif( $attachment_path );
$city = get_post_meta( $post->ID, 'city', true );
$locationname = get_post_meta( $post->ID, 'locationname', true );
$form_fields['city'] = array(
'label' => 'City',
'input' => 'text',
'value' => !empty($city) ? $city : $metadata['city'],
'helps' => '',
);
$form_fields['locationname'] = array(
'label' => 'Location name',
'input' => 'text',
'value' => !empty($locationname) ? $locationname : $metadata['locationname'],
'helps' => '',
);
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'display_exif_fields', 10, 2 );
function save_exif_fields( $post, $attachment ) {
$array = [ 'city', 'locationname' ];
foreach ( $array as $one ) {
if ( ! empty( $attachment[ $one ] ) ) {
update_post_meta( $post[ 'ID' ], $one, $attachment[ $one ] );
} else {
delete_post_meta( $post[ 'ID' ], $one );
}
}
return $post;
}
add_filter( 'attachment_fields_to_save', 'save_exif_fields', 10, 2 );
add_action( 'woocommerce_cart_calculate_fees', 'wpp_custom_surcharge' );
function wpp_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$percentage = 0.15;
$time = date( 'H' );
if ( 11 <= (int) $time && 12 > (int) $time ) :
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Счастливый час', - $surcharge, true, '' );
endif;
}
function trim_custom_excerpt( $excerpt ) {
if ( has_excerpt() ) {
$excerpt = wp_trim_words( get_the_excerpt(), apply_filters( "excerpt_length", 55 ) );
}
return $excerpt;
}
add_filter( "the_excerpt", "trim_custom_excerpt", 999 );
$files = $_FILES[ "photo" ];
$_ids = $_errors = [];
foreach ( $files[ 'name' ] as $key => $value ) {
if ( $files[ 'name' ][ $key ] ) {
$file = array (
'name' => $files[ 'name' ][ $key ],
'type' => $files[ 'type' ][ $key ],
'tmp_name' => $files[ 'tmp_name' ][ $key ],
'error' => $files[ 'error' ][ $key ],
'size' => $files[ 'size' ][ $key ]
);
$_FILES = array ( "rev_foto" => $file );
$attachment_id2 = media_handle_upload( "rev_foto", 0 );
if ( is_wp_error( $attachment_id2 ) ) {
$_errors[] = $attachment_id2->get_error_message();
} else {
$_ids[] = $attachment_id2;
}
}
}
if ( ! empty( $_ids ) ) {
update_field( 'rev_foto', $_ids, $post_id );
}
if ( ! empty( $_errors ) ) {
sprintf( 'А вот, что пошло не так: %s', implode( ' ,', $_errors ) );
}
$_flag = []; // онтрольный массив
if ( have_posts() ) : while ( have_posts() ) : the_post();
$first = mb_substr( get_the_title(), 0, 1 );
if ( ! in_array( $first, $_flag ) ) { //проверка на наличие первой буквы в массиве
// если ее там нет, выводим букву и добавляем в контрольный мавссив
printf( '<h3>%s</h3>', $first );
$_flag[] = $first;
}
/**
* тут выод записи
*/
endwhile;
else :
endif;
add_filter( 'wpcf7_form_elements', 'wpcf7_remove_span_wrapper' );
function wpcf7_remove_span_wrapper( $content ) {
$str_pos = strpos( $content, 'target-class' );
if ( $str_pos !== false ) {
$content = preg_replace( '/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content );
$content = str_replace( '<br />', '', $content );
}
return $content;
}