<?php $field = get_field('acf-croup'); if(/*можно даже перестраховаться и сделать isset($field) && */ !empty($field) ): /* Если поле не пустое то: */ ?>
<tr class="table__row">
<th class="table__cell table__cell_head">Модуль крупности</th>
<td class="table__cell"><?= $croup ? $croup : '-'; ?></td>
</tr>
<?php endif; ?>
берет что-то из текущей опции списка
jQuery('#client_surename').on('focusout',function(){
var now = new Date(Date.now());
if(jQuery('#client_login').val() ==''){ jQuery('#client_login').val( cyr2lat_login (jQuery('#client_surename').val()+now.getHours()+now.getMinutes()+now.getSeconds() ) ); }
jQuery('#client_login').trigger('change');
})
$man="Петя"; $woman = "Маша";
$result = get_option("action");
if($result=="послала" && $typeof($man)!="Man") { petya_die(); } else{ return $woman.' '.$result.' '.$man;}
<?php
/*
Plugin Name: jQuery-Plugin_Includer
Plugin URI: http://александрсоболев.рф
Description: Плагин подключающий jQuery скрипты
Version: 1.0
Author: Александр Соболев
Author URI: http://vk.com/san_jorich
License: GPL2
*/
/* Copyright 2018 SOBOLEV_ALEKSANDER (email : samigrai@mail.ru) */
function js_includer() {
wp_register_script('нужная_вам_библиотека\плагин', plugins_url('js/нужная_вам_библиотека\плагин.js', __FILE__));
wp_enqueue_script('нужная_вам_библиотека\плагин');
wp_register_script('js_обработчик', plugins_url('js/js_обработчик.js', __FILE__));
wp_enqueue_script('js_обработчик');
wp_localize_script( 'js_обработчик', 'ajaxurl', admin_url( 'admin-ajax.php' ) ); // Чтоб работали ajax запросы
}
add_action( 'admin_enqueue_scripts', 'js_includer' ); // Подключение JS-скриптов в админке
add_action( 'wp_enqueue_scripts', 'js_includer' ); // Подключение JS-скриптов в фронтэнде
?>
function custom_wpcf7_validator( $array ) {
$stopcode = $array['secret_input'];
if( !empty( $stopcode ) ){ break; } else { return $array; }
};
add_filter( 'custom_wpcf7_validator', 'action_wpcf7_posted_data', 9, 1 ); // Только с приоритетом нужно разобраться.. и с массивом
$es_admin_capabilities=array(
/* standart capabilities */
'activate_plugins' => false,
'delete_others_pages' => false,
'delete_others_posts' => false,
'delete_pages' => false,
'delete_posts' => false,
'delete_private_pages' => false,
'delete_private_posts' => false,
'delete_published_pages'=> false,
'delete_published_posts'=> false,
'edit_dashboard' => true,
'edit_others_pages' => false,
'edit_others_posts' => false,
'edit_pages' => false,
'edit_posts' => false,
'edit_private_pages' => false,
'edit_private_posts' => false,
'edit_published_pages' => false,
'edit_published_posts' => false,
'edit_theme_options' => false,
'export' => false,
'import' => false,
'list_users' => false,
'manage_categories' => false,
'manage_links' => false,
'manage_options' => true, // поидее должен пускать в админку но.. не хочет
'moderate_comments' => false,
'promote_users' => false,
'publish_pages' => false,
'publish_posts' => false,
'read_private_pages' => false,
'read_private_posts' => false,
'read' => false,
'remove_users' => false,
'switch_themes' => false,
'upload_files' => false,
'customize' => false,
'delete_site' => false,
/* es_event taxonomy capabilities */
'edit_es_event' => true,
'edit_others_es_event' => true,
'publish_es_event' => true,
'read_private_es_event' => true,
'delete_es_event' => true,
'delete_private_es_event'=> true,
'delete_published_es_event'=>true,
'delete_others_es_event' => true,
'edit_private_es_event' => true,
'edit_published_es_event'=> true,
);
function get_es_role_capabilities($role){
switch ($role) {
case 'es_admin': return $es_admin_capabilities; break;
}
}
register_activation_hook( __FILE__, 'add_se_roles' );
function add_se_roles() {
//require_once(dirname(__FILE__) . '/functions_php/es_users_managment.php');
add_role('es_admin', 'Администратор Системы Мероприятий', get_es_role_capabilities('es_admin'));
}
<div class="row photo2estate ml-3" id="estate_photos">
<label for="photos">Фотографии объекта</label>
<div id="photos" class = "col-md-12"><?php get_estate_photos($estate_object_id);?></div>
<div class = "col-md-3 upload-form">
<div class= "upload-response"></div>
<div class = "form-group">
<label>Выберите файлы:</label>
<input type = "file" name = "files[]" accept = "image/*" class = "files-data form-control" multiple />
</div>
<div class = "form-group">
<input type = "submit" value = "Загрузить" estate_id="<?php echo $estate_object_id;?>" class = "btn btn-primary btn-upload" />
</div>
</div>
</div>
// Функция загрузки изображений
add_action('wp_ajax_ae_upload_files', 'ae_upload_files');
add_action('wp_ajax_nopriv_ae_upload_files', 'ae_upload_files'); // Allow front-end submission
function ae_upload_files(){
$estate_id = isset( $_POST['estate_id'] ) ? $_POST['estate_id'] : 0; // The parent ID of our attachments
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg"); // Supported file types
$max_file_size = 4096 * 2000; // in kb
$max_image_upload = 40;
$wp_upload_dir = wp_upload_dir();
$path = $wp_upload_dir['path'] . '/';
$count = 0;
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $estate_id,
'exclude' => get_post_thumbnail_id()
) );
if( $_SERVER['REQUEST_METHOD'] == "POST" ){
if( ( count( $attachments ) + count( $_FILES['files']['name'] ) ) > $max_image_upload ) {
$upload_message[] = "Лимит возможных фотографий = " . $max_image_upload . " превышен. За подробностями обратитесь к администратору системы";
} else {
foreach ( $_FILES['files']['name'] as $f => $name ) {
$extension = pathinfo( $name, PATHINFO_EXTENSION );
// Generate a randon code for each file name
$new_filename = 'estate_'.$estate_id.'-img_'.ae_generate_random_code( 5 ) . '.' . $extension;
if ( $_FILES['files']['error'][$f] == 4 ) { continue; }
if ( $_FILES['files']['error'][$f] == 0 ) {
if ( $_FILES['files']['size'][$f] > $max_file_size ) { $upload_message[] = "$name слишком большой!"; continue; }
elseif( ! in_array( strtolower( $extension ), $valid_formats ) ){ $upload_message[] = "$name формат файла не поддерживается!"; continue; }
else{
if( move_uploaded_file( $_FILES["files"]["tmp_name"][$f], $path.$new_filename ) ) {
$count++;
$filename = $path.$new_filename;
$filetype = wp_check_filetype( basename( $filename ), null );
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $estate_id );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
}
}
}
}
}
}
if ( isset( $upload_message ) ) :
foreach ( $upload_message as $msg ){
printf( __('<p class="bg-danger">%s</p>', 'wp-trade'), $msg );
}
endif;
// If no error, show success message
if( $count != 0 ){ printf( __('<p class = "bg-success">Изображения загруженны успешно!</p>', 'wp-trade'), $count ); } exit();
}
// Random code generator used for file names.
function ae_generate_random_code($length=6) {
$string = '';
$characters = "23456789ABCDEFHJKLMNPRTVWXYZabcdefghijklmnopqrstuvwxyz";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters)-1)];
}
return $string;
}
jQuery(document).ready(function() {
jQuery('body').on('click', '.btn-upload', function(e){
e.preventDefault;
var estate_id = jQuery(this).attr('estate_id');
var fd = new FormData();
var files_data = jQuery('.upload-form .files-data');
jQuery.each(jQuery(files_data), function(i, obj) {
jQuery.each(obj.files,function(j,file){
fd.append('files[' + j + ']', file);
})
});
fd.append('action', 'ae_upload_files');
// Remove this code if you do not want to associate your uploads to the current page.
fd.append('estate_id', estate_id);
jQuery.ajax({
type: 'POST',
url: ajaxurl,
data: fd,
contentType: false,
processData: false,
success: function(response){
swal('Успешно!','Фотографии успешно загруженны!','success')
//jQuery('.upload-response').html(response); // Append Server Response
}
});
});
});
<?php
/*
Plugin Name: File Download Counter
Plugin URI: http://александрсоболев.рф
Description: Плагин-виджет, реализующий счетчик кликов
Author: Александр Соболев
Version: 1.1
Author URI: http://александрсоболев.рф
*/
function js_includer() { wp_register_script('my_click_counter', plugins_url('js/my_click_counter.js', __FILE__)); wp_enqueue_script('my_click_counter'); wp_localize_script( 'my_click_counter', 'ajaxurl', admin_url('admin-ajax.php') );}
function register_my_counter() { register_setting( 'my_click_counter', 'counter', 'intval' ); }
function count_plus(){$all_options = get_option('my_click_counter'); $count = intval($all_options['counter']); $new_val= ++$count;update_option( 'my_click_counter', $new_val ); wp_send_json($new_val); }
function show_counter(){get_option('my_click_counter'); $count = intval($all_options['counter']); $counter_div='<div id="my_counter_accept">Тест счечика.</div><div id="my_click_counter">'.$counter_div.'</div>';return $counter_div;} add_shortcode( 'show_counter', 'show_counter' );
add_action( 'admin_enqueue_scripts', 'js_includer' ); add_action( 'wp_enqueue_scripts', 'js_includer' ); add_action( 'admin_init', 'register_my_counter' ); add_action( 'wp_ajax_count_plus','count_plus' ); add_action( 'wp_ajax_nopriv_count_plus','count_plus' );
?>
jQuery(document).ready(function(){
jQuery('#my_counter_accept').on('click',function(){
jQuery.ajax({ type: "POST", url: ajaxurl, dataType: 'json', data: { action: 'count_plus'}, beforeSend: function(){jQuery('.класс ссылки').remove(); }, success: function(new_val) { console.log('Файл скачен '+new_val+' раз'); } });
})
});