Skip to content

Instantly share code, notes, and snippets.

Rosca Bogdan roscabgdn

Block or report user

Report or block roscabgdn

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@roscabgdn
roscabgdn / query-by-cat.php
Last active May 22, 2019
Query posts by category
View query-by-cat.php
<?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 Jul 26, 2018
Remove "Billing" text from wc notice errors
View gist:7d06a4b0f8deb5c94b7c04a11d715ed3
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 Mar 15, 2018
htaccess for leverage browser caching
View .htaccess
# 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 Jul 3, 2017
Add post featured image as rss node
View add_image_to_rss_wp
// 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 Feb 14, 2017 — 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.
View array-insert-after.php
<?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 Dec 16, 2016
# BLOCK PROXY VISITS
View .htaccess
# 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 Oct 17, 2016
Rewrite - add /blog/post-name to posts
View new-rewrite.php
/**
* 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 Jun 7, 2016
Programmatically Create a User in WordPress
View gist:d6a709116ae90ad8beda81b60ed9fb27
$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 Dec 21, 2017
Advanced WordPress Security Tips
View security-tips.php
/*
* 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!';
}
@roscabgdn
roscabgdn / .htaccess
Last active Apr 25, 2016
# WHITELISTING IP ADDRESSES
View .htaccess
# WHITELISTING IP ADDRESSES
<Files wp-login.php>
Order Deny,Allow
Deny from all
# Allow access via this IP address
Allow from xxx.xxx.xxx.xxx
</Files>
You can’t perform that action at this time.