211
правок
8j0rn (обсуждение | вклад) Нет описания правки |
8j0rn (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
=1. Мелкие доработки= | |||
==1.1. Добавляем favicon== | |||
<syntaxhighlight lang="php"> | |||
// Добавляем favicon | |||
function _8j0rn_add_custom_favicon() { | |||
echo '<link rel="icon" href="' . home_url('/favicon.png') . '" type="image/png">'; | |||
} | |||
add_action('wp_head', '_8j0rn_add_custom_favicon'); | |||
</syntaxhighlight> | |||
==1.2. Настраиваем robots.txt== | |||
<syntaxhighlight lang="php"> | |||
// Настраиваем robots.txt | |||
add_action( 'do_robotstxt', 'my_robotstxt' ); | |||
function my_robotstxt(){ | |||
$lines = [ | |||
'User-agent: *', | |||
'', | |||
'Disallow: /wp-admin/', | |||
'Allow: /wp-admin/admin-ajax.php', | |||
'', | |||
'Disallow: /wp-includes/', | |||
'Disallow: /subjects/*', | |||
'Disallow: /cgi-bin/*', | |||
'Disallow: /wp-admin/*', | |||
'Disallow: /wp-includes/*', | |||
'Disallow: /wp-content/plugins/*', | |||
'Disallow: /wp-content/cache/*', | |||
'Disallow: /wp-content/themes/*', | |||
'Disallow: /wp-trackback*', | |||
'Disallow: /wp-feed*', | |||
'Disallow: /wp-comments*', | |||
'Disallow: /category/*', | |||
'Disallow: /author/*', | |||
'Disallow: /page/*', | |||
'Disallow: /tag/*', | |||
'Disallow: /feed/*', | |||
'Disallow: */feed', | |||
'Disallow: */trackback', | |||
'Disallow: */comments', | |||
'Disallow: /*?', | |||
'Disallow: /*?*', | |||
'Disallow: /*.php', | |||
'', | |||
'Sitemap: /sitemap_index.xml', | |||
'', | |||
]; | |||
echo implode( "\r\n", $lines ); | |||
die; // обрываем работу PHP | |||
} | |||
</syntaxhighlight> | |||
==1.3. Изменение места загрузки фотографий== | |||
<syntaxhighlight lang="php"> | |||
// Изменение места загрузки фотографий | |||
function custom_upload_dir( $uploads ) { | |||
$time = current_time( 'mysql' ); | |||
$uploads['subdir'] = '/photo/' . substr( $time, 0, 4 ) . '/' . substr( $time, 5, 2 ) . '/' . substr( $time, 8, 2 ); | |||
$uploads['path'] = $uploads['basedir'] . $uploads['subdir']; | |||
$uploads['url'] = $uploads['baseurl'] . $uploads['subdir']; | |||
return $uploads; | |||
} | |||
</syntaxhighlight> | |||
==1.4. Изменяем имя медиа-файла== | |||
<syntaxhighlight lang="php"> | |||
// Изменяем имя медиа-файла | |||
function custom_upload_file_name($file) { | |||
$prefix = 'RecordInvest'; | |||
$filename = $file['name']; | |||
$ext = pathinfo($filename, PATHINFO_EXTENSION); | |||
$date = date('Y-m-d'); | |||
$post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0; | |||
$num = 1; | |||
$new_filename = "{$prefix}_{$date}_{$post_id}_{$num}.{$ext}"; | |||
while (file_exists($file['path'] . '/' . $new_filename)) { | |||
$num++; | |||
$new_filename = "{$prefix}_{$date}_{$post_id}_{$num}.{$ext}"; | |||
} | |||
$file['name'] = $new_filename; | |||
return $file; | |||
} | |||
add_filter('wp_handle_upload_prefilter', 'custom_upload_file_name'); | |||
</syntaxhighlight> | |||
=2. Добавление Magnific Popup и fancybox без плагина= | |||
==2.1. Добавление Magnific Popup== | |||
<syntaxhighlight lang="php"> | |||
// Добавляем magnific_popup js script и css | |||
function enqueue_magnific_popup() { | |||
// Получаем URL директории плагина, поскольку в моем случае расположение папки с Magnific Popup находится в директории плагина. | |||
$plugin_url = plugin_dir_url(__FILE__); | |||
// Подключение Magnific Popup CSS | |||
wp_enqueue_style('magnific-popup', $plugin_url . '<<---папка-расположения-файлов-magnific-popup--->>/magnific-popup.css'); | |||
// Подключение Magnific Popup JS | |||
wp_enqueue_script('magnific-popup', $plugin_url . '<<---папка-расположения-файлов-magnific-popup--->>/jquery.magnific-popup.min.js', array('jquery'), null, true); | |||
// Инициализация Magnific Popup для кнопок | |||
wp_add_inline_script('magnific-popup', ' | |||
jQuery(document).ready(function($) { | |||
$(".epl-button").on("click", function() { | |||
var imageUrl = $(this).attr("data-image"); // Получаем URL изображения | |||
var caption = $(this).attr("data-caption"); // Получаем подпись | |||
$.magnificPopup.open({ | |||
items: { | |||
src: imageUrl | |||
}, | |||
type: "image", | |||
closeOnContentClick: true, | |||
mainClass: "mfp-img-mobile", | |||
image: { | |||
verticalFit: true, | |||
titleSrc: caption // Добавляем подпись | |||
} | |||
}); | |||
}); | |||
}); | |||
'); | |||
} | |||
add_action('wp_enqueue_scripts', 'enqueue_magnific_popup'); | |||
</syntaxhighlight> | |||
==2.2. Добавление fancybox== | |||
<syntaxhighlight lang="php"> | |||
// Добавляем fancybox js script и css | |||
function enqueue_fancybox() { | |||
// Получаем URL директории плагина, поскольку в моем случае расположение папки с Magnific Popup находится в директории плагина. | |||
$plugin_url = plugin_dir_url(__FILE__); | |||
// Подключение Fancybox CSS (если он тоже в той же папке) | |||
wp_enqueue_style('fancybox', $plugin_url . '<<---папка-расположения-файлов-magnific-popup--->>/fancybox.css'); | |||
// Подключение Fancybox JS (fancybox.umd.js в той же папке) | |||
wp_enqueue_script('fancybox', $plugin_url . '<<---папка-расположения-файлов-magnific-popup--->>/fancybox.umd.js', array('jquery'), null, true); | |||
// Инициализация Fancybox для кнопок | |||
wp_add_inline_script('fancybox', ' | |||
jQuery(document).ready(function($) { | |||
$(".epl-button").on("click", function() { | |||
var imageUrl = $(this).attr("data-image"); // Получаем URL изображения | |||
var caption = $(this).attr("data-caption"); // Получаем подпись | |||
$.fancybox.open({ | |||
src: imageUrl, | |||
type: "image", | |||
opts: { | |||
caption: caption | |||
} | |||
}); | |||
}); | |||
}); | |||
'); | |||
} | |||
add_action('wp_enqueue_scripts', 'enqueue_fancybox'); | |||
</syntaxhighlight> | |||