Skip to content

Instantly share code, notes, and snippets.

@zevilz
zevilz / wp_remove_attachments.sh
Last active March 21, 2023 16:26
Remove old WP attachments
#!/bin/bash
while true; do
POSTS=$(wp db query 'SELECT ID FROM wp_posts WHERE post_type="attachment" AND post_date < "2022-06-05" LIMIT 10000;' --skip-column-names | paste -s -d ' ' -)
if ! [ -z "$POSTS" ]; then
wp post delete $POSTS --force
else
exit 0
fi
done
/* fixes */
body {-webkit-text-size-adjust: 100% !important;}
html * {max-height:1000000px; min-height: 0; min-width: 0;}
body,
body * {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
vertical-align: middle;
}
# main
location / {
index index.php;
try_files $uri $uri/ @bitrix;
}
location @bitrix {
fastcgi_pass unix:/run/php/phpX.X-fpm.$pool_name.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/bitrix/urlrewrite.php;
@zevilz
zevilz / cf_cache_options.php
Created August 12, 2019 10:22
Function for get cached carbon fields option or get it if it not isset in cache
<?php
/**
* Gets cached carbon fields option or get it if it not isset in cache
*
* @param string $option Option name
*
* @return mixed
*/
function carbon_get_theme_option_cached( $option ) {
$option_value = wp_cache_get( $option, 'crb_options' );
@zevilz
zevilz / add_meta_to_search.php
Created July 25, 2019 10:35
Include post meta fields in WP search.
<?php
/**
* Add post meta to search query in where part
*
* @param string $where Where query part
*
* @return string
*/
function modify_wp_search_where( $where ) {
if ( is_search() ) {
@zevilz
zevilz / cf_seo_progressbars.js
Last active July 16, 2019 14:01
cf_seo_progressbars
function getProgressClass(type, value) {
if ( type == 'meta_t' ) {
if (value < 400) {
var progress_class = 'ok';
}
else if (value > 600) {
var progress_class = 'bad';
}
else {
var progress_class = 'good';
{
"annotations": {
"list": [
{
"$$hashKey": "object:143",
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
@zevilz
zevilz / wp_register_cpt_with_tax.php
Last active July 23, 2018 05:49
Register custom post type with custom taxonomy for wordpress. Post type link include taxonomy term.
<?php
/*
*
* Register post type "service"
*
*/
add_action('init', 'register_service', 0);
function register_service() {
register_post_type('service', [
'label' => null,
@zevilz
zevilz / wp_hide_dashboard.php
Last active October 29, 2017 06:29
Hide dashboard in Wordpress
/*
*
* Hide dashboard page from admin menu
*
*/
function remove_menus() {
remove_menu_page('index.php');
}
add_action('admin_menu', 'remove_menus');
@zevilz
zevilz / extract.sh
Last active August 6, 2017 08:55
Extract data for connections to db for all WP sites in folder
#!/bin/bash
# folder with sites
INPUT_DIR='/home/'
# path to file for data
OUTPUT_FILE='data.txt'
find $INPUT_DIR -name 'wp-config.php' > /tmp/files.txt
echo -n > $OUTPUT_FILE