Содержание

CMS: WordPress

Хомпэйдж, доки, лалала


GoD Bless

Спасибо следующим статьям, которые сэкономили мне много времени.

Шаблоны

Bootstrap based themes

Хаки спамы куки

Плагины

Разное

Карта сайта

Yoast

Разное

Запрет выполнения кода

Options -Indexes
php_flag engine 0
RemoveHandler .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml
AddType application/x-httpd-php-source .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml

Как перенести сайт WP с одного домена на другой?

Через Search Replace DB, github.

Мини-статистика ram/sql/time

<?php
echo "Статистика:" . get_num_queries() . "/ "; timer_stop(1);
echo "s/ ". round(memory_get_usage()/1024/1024, 2) . " MB ";
?>

Мини-статистика ram/sql/time #2

В стиле LiveInternet

<!-- WORDPRESS STATISTICS -->
 <div style="line-height: 10px; display: block; text-align: left; font-family: Tahoma; width: 88px; height:31px; border: 0px; background: #e7e7e7; font-size: 7pt;">
 <span style="color: #555555;">Generated by:</span> <?php timer_stop(1); ?>
 <span style="color: #555555;">Queries:</span> <?php echo get_num_queries(); ?>
 <span style="color: #555555;">Memory:</span> <?php if (function_exists('memory_get_usage')) echo round(memory_get_usage()/1024/1024, 2) . 'MB '; ?>
 </div>
<!-- /WORDPRESS STATISTICS -->

Проверка работы почты

Файл в корневой директории WP

<?php
 
        // Set $to as the email you want to send the test to.
 
$to = "[email protected]" ;
 
       // No need to make changes below this line.
       // Email subject and body text.
 
$subject = ' wp_mail function test ' ;
$message = ' This is a test of the wp_mail function: wp_mail is working ' ;
$headers = '' ;
 
      // Load WP components, no themes.
 
define ('WP_USE_THEMES', false);
 
require('wp-load.php');
 
     // send test message using wp_mail function.
 
$sent_message = wp_mail( $to, $subject, $message, $headers);
 
     //display message based on the result.
 
if ( $sent_message ) {
 
    // The message was sent.
echo 'The test message was sent. Check your email inbox.' ;
 
} else {
 
    // The message was not sent.
echo 'The message was not sent!' ;
}

htaccess по-умолчанию

# BEGIN WordPress Permalinks
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress Permalinks

Лимит памяти для Wordpress

Для wp-admin

define('WP_MAX_MEMORY_LIMIT', '1024M');

Для frontend

define('WP_MEMORY_LIMIT', '512M');

Еще один пример time used

// Script start
$rustart = getrusage();

// Code ...

// Script end
function rutime($ru, $rus, $index) {
    return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000))
     -  ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000));
}

$ru = getrusage();
echo "This process used " . rutime($ru, $rustart, "utime") .
    " ms for its computations\n";
echo "It spent " . rutime($ru, $rustart, "stime") .
    " ms in system calls\n";

via

Отключить превью для ссылок twitter в постах

https://wordpress.org/support/article/embeds/

Через плагин, через код

Пересоздание миниатюр

Печальная новость. Автор плагина Regenerate Thumbnails Viper007Bond Alex Mills после долгой борьбы с болезнью ныне RIP.

Вероятно сообщество Wordpress позаботится о коде.

Альтернативно для работы с миниатюрами можно использовать wp-cli.

undefined function trailingslashit()

Fatal error: Uncaught Error: Call to undefined function trailingslashit() in /var/www/rtfm/data/www/foobar.com/wp-includes/class-wp-textdomain-registry.php:103
...

установить php-psr

Убрать ограничение 2560 px для загружаемых изображений

Через плагин

code snippet плагин

<?php
// Disable WordPress' automatic image scaling feature
add_filter( 'big_image_size_threshold', '__return_false' );

functions.php

add_filter( 'big_image_size_threshold', '__return_false' );

изменить размер

function custom_image_threshold( $threshold ) {
   return 4000; // new threshold
}
add_filter('big_image_size_threshold', 'custom_image_threshold', 999, 1);