Skip to content

Instantly share code, notes, and snippets.

@roscabgdn
roscabgdn / customizer.php
Created February 11, 2021 08:48
Add elements in customizer: panels, sections, settings.
<?php
// In folderul themes creati un folder inc daca nu-l aveti deja.
// In acest folder creati un fisier customizer.php
// ( el poate sa fie salvat si sub alt nume, eu doar am pus acest nume pentru ca e sugestiv).
// In interiorul acestui fisier (customizer.php) copy paste la functia prefix_customizer_register.
// prefix_ ar trebui inlocuit cu numele theme-ului vostru. Ex: bogdan_customizer_register
// La fel si textdomain-ul.
function prefix_customizer_register( $wp_customize ) {
@roscabgdn
roscabgdn / query-by-cat.php
Last active May 22, 2019 13:13
Query posts by category
<?php
// Query arguments : https://codex.wordpress.org/Class_Reference/WP_Query
$args = array(
'posts_per_page'=> 5,
'orderby' => 'date',
'order' => 'DESC',
'category' => 'slider'
);
// create the query
@roscabgdn
roscabgdn / gist:7d06a4b0f8deb5c94b7c04a11d715ed3
Created July 26, 2018 12:00
Remove "Billing" text from wc notice errors
function rbpixel_customize_wc_errors( $error ) {
if ( strpos( $error, 'Billing ' ) !== false ) {
$error = str_replace("Billing ", "", $error);
}
return $error;
}
add_filter( 'woocommerce_add_error', 'rbpixel_customize_wc_errors' );
@roscabgdn
roscabgdn / .htaccess
Created March 15, 2018 09:07
htaccess for leverage browser caching
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@roscabgdn
roscabgdn / add_image_to_rss_wp
Created July 3, 2017 10:20
Add post featured image as rss node
// Add the image node to RSS feed
add_action('rss2_item', 'add_featured_image_as_rss_node');
function add_featured_image_as_rss_node() {
global $post;
if(has_post_thumbnail($post->ID)):
$thumbnail = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
echo("<image>{$thumbnail}</image>");
endif;
}
@roscabgdn
roscabgdn / array-insert-after.php
Created February 14, 2017 10:40 — forked from wpscholar/array-insert-after.php
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@roscabgdn
roscabgdn / .htaccess
Created December 16, 2016 14:54
# BLOCK PROXY VISITS
# BLOCK PROXY VISITS
# PerishablePress.com: http://bit.ly/12k6Uo
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP:VIA} !^$ [OR]
RewriteCond %{HTTP:FORWARDED} !^$ [OR]
RewriteCond %{HTTP:USERAGENT_VIA} !^$ [OR]
RewriteCond %{HTTP:X_FORWARDED_FOR} !^$ [OR]
RewriteCond %{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION} !^$ [OR]
@roscabgdn
roscabgdn / new-rewrite.php
Created October 17, 2016 09:54
Rewrite - add /blog/post-name to posts
/**
* Add new rewrite rule
*/
function create_new_url_querystring() {
add_rewrite_rule(
'blog/([^/]*)$',
'index.php?name=$matches[1]',
'top'
);
add_rewrite_tag('%blog%','([^/]*)');
@roscabgdn
roscabgdn / gist:d6a709116ae90ad8beda81b60ed9fb27
Created June 7, 2016 08:20
Programmatically Create a User in WordPress
$user_name = 'username';
$user_email = 'email';
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$user_id = username_exists( $user_name );
if ( !$user_id and email_exists($user_email) == false ) {
$user_id = wp_create_user( $user_name, $random_password, $user_email );
$user = get_user_by( 'id', $user_id );
// Remove role
$user->remove_role( 'subscriber' );
@roscabgdn
roscabgdn / security-tips.php
Last active January 29, 2024 09:06
Advanced WordPress Security Tips
/*
* this code goes in your theme`s functions.php file
*/
add_filter('login_errors',create_function('$a', "return null;"));
define( 'DISALLOW_FILE_EDIT', true );
function no_wordpress_errors(){
return 'Nothing to see here, move along!';
}