Skip to content

Instantly share code, notes, and snippets.

View moskalukigor's full-sized avatar

Ihor moskalukigor

View GitHub Profile
@moskalukigor
moskalukigor / functions.php
Last active December 16, 2022 11:48
update YoastSEO title and description with qTranslate
<?php
add_action('wp', function(){
global $wpdb;
$seo_title = "[:uk]TEST TITLE😜[:en]TEST TITLE😜[:]";
$seo_description = "[:uk]Test description 👍[:en]Test description 👍[:]";
$sql = "SELECT option_value FROM wp_options WHERE option_name = 'wpseo_taxonomy_meta'";
$result = $wpdb->get_results($sql);
@moskalukigor
moskalukigor / index.js
Created May 7, 2022 09:02
Javascript search by xpath
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
console.log( getElementByXpath("//html[1]/body[1]/div[1]") );
@moskalukigor
moskalukigor / qtranslate_core.php
Created April 13, 2021 11:55
q-Translate remove 302 redirect. Need to overwrite qtranslate_core.php
<?php
$target = apply_filters( 'qtranslate_language_detect_redirect', $url_lang, $url_orig, $url_info );
if ( $target !== false && $target != $url_orig ) {
//Custom code Start
$urlToArray = explode('/', $url_orig);
if(end($urlToArray) != "")
{
$target .= '/';
}
//Custom code End
@moskalukigor
moskalukigor / Add custom page to buddypress profile
Created April 7, 2021 13:11 — forked from modemlooper/php
Example on adding a page to user profile
<?php
/**
* Plugin Name: BP Add Page
* Plugin URI: https://webdevstudios.com
* Description: Example on adding a page to BuddyPress profiles
* Author: WebDevStudios
* Author URI: https://webdevstudios.com
* Version: 1.0.0
* License: GPLv2
*/
@moskalukigor
moskalukigor / functions.php
Last active October 24, 2018 09:41
Show only user loaded images in ACF Gallery in frontend using acf_form | And grant user permission to upload files and change published page
<?php
$role = new WP_User( $userID );
$role->add_cap('upload_files', true);
$role->add_cap('edit_published_pages', true);
add_filter( 'posts_where', 'devplus_attachments_wpquery_where' );
function devplus_attachments_wpquery_where( $where ){
global $current_user;
@moskalukigor
moskalukigor / function.php
Created October 19, 2018 12:14
View All without pagination Shop Products Woocommerce
<?php
remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination', 10);
add_action('woocommerce_after_shop_loop', 'customPagination');
function customPagination()
{
if($_GET['view'] != 'all'){
echo '<div class="product-view-all"><a href="?view=all">View All</a></div>';
}
}
@moskalukigor
moskalukigor / index.js
Last active October 10, 2018 13:03
Update object (Nested) with react-addons-update
import update from 'react-addons-update';
let nextState = update(this.state.cards, {
[index] : {
tasks: {$splice: [[taskIndex, 1]]}
}
});
//-----------------------------------------------------
@moskalukigor
moskalukigor / function.php
Last active October 5, 2018 11:57
Add shortcode in cf7 with plugin Listo
<?php
add_filter('listo_list_types', 'listo_list_types_func');
function listo_list_types_func($list_types){
$list_types['physicians'] = 'Listo_Physicians';
return $list_types;
}
class Listo_Physicians implements Listo {
public static function items(){
@moskalukigor
moskalukigor / functions.php
Created August 10, 2018 07:28
remove all items from cart exclude new
<?php
add_action( 'woocommerce_add_to_cart', 'remove_cart2',10 , 6 );
function remove_cart2($cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data){
global $woocommerce;
if ($woocommerce->cart->get_cart_contents_count() != 0) {
$cartQty = $woocommerce->cart->get_cart_item_quantities();
$cartItems = $woocommerce->cart->cart_contents;
// Check if desired product is in cart already
@moskalukigor
moskalukigor / functions.php
Created July 16, 2018 13:12
Gravity forms image size ( width , height ) validation
<?php
function limit_file_upload_size( $validation_result ) {
$images = json_decode(json_decode('"'.$_POST['gform_uploaded_files'].'"', true));
$form = $validation_result['form'];
foreach( $form['fields'] as &$field ){
$is_hidden = RGFormsModel::is_field_hidden( $form, $field, array() );