Skip to content

Instantly share code, notes, and snippets.

View zarei-dev's full-sized avatar
💻
Focusing

Mohammad Zarei zarei-dev

💻
Focusing
View GitHub Profile
@zarei-dev
zarei-dev / functions.php
Created January 29, 2023 13:30
Nofollow all external links inside posts
<?php
// nofollow all external links in posts and pages
add_filter('the_content', 'vc_nofollow');
add_filter('the_excerpt', 'vc_nofollow');
function vc_nofollow($content) {
return preg_replace_callback('/<a[^>]+/', 'vc_nofollow_callback', $content);
}
function vc_nofollow_callback($matches) {
@zarei-dev
zarei-dev / Coupon.php
Created September 18, 2022 07:48
Create WooCommerce Coupon
<?php
defined( 'ABSPATH' ) || exit;
class Coupon {
private $amount;
private $discount_type;
private $coupon_code = null;
@zarei-dev
zarei-dev / Change_allowed_mime_types_WP.php
Last active June 19, 2022 16:14
Change allowed mime_types in WordPress conditionally with plupload
<?php
add_filter( 'plupload_init', function( $plupload_init ) {
if ( isset($_GET['page']) && $_GET['page'] == 'vod-videos-add') {
$plupload_init['filters']['mime_types'] = [
array(
'title' => 'Videos',
'extensions' => 'mp4,mov,m4v',
'mime_types' => 'video/mp4,video/quicktime,video/x-m4v',
@zarei-dev
zarei-dev / disable-file-editor.php
Created March 28, 2022 03:40
Disable file editing tool in your WordPress admin panel.
<?php
if( !defined('DISALLOW_FILE_EDIT') ){
define( 'DISALLOW_FILE_EDIT', true );
}
@zarei-dev
zarei-dev / filters.php
Created February 26, 2022 06:13
Dequeue recaptcha from not needed pages
<?php
/**
* Dequeue recaptcha from not needed pages
*/
add_action('wp_enqueue_scripts', function () {
global $post;
if ( is_a( $post, 'WP_Post' ) && !has_shortcode( $post->post_content, 'contact-form-7') ) {
wp_dequeue_script('google-recaptcha');
add_filter( 'wpcf7_load_js', '__return_false' );
@zarei-dev
zarei-dev / woocommerce_attributes_query.sql
Last active January 19, 2022 05:26
woocommerce attributes sql query
SELECT
t.term_id AS 'Attribute Value ID',
tt.taxonomy AS 'Attribute Name',
wat.attribute_label AS 'Attribute Label',
t.name AS 'Attribute Value',
COUNT(t.name) as 'num'
FROM
wp_posts AS p
INNER JOIN wp_term_relationships AS tr
ON
@zarei-dev
zarei-dev / woo.php
Created December 25, 2021 12:40
disable cart functionality woocommerce
<?php
// Remove cart button from mini-cart
remove_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
// Add checks and notices
add_action( 'admin_notices', function() {
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
?><div class="notice notice-error"><p><?php _e( 'Warning! To use Disable cart page for WooCommerce it need WooCommerce is installed and active.', 'disable-cart-page-for-woocommerce' ); ?></p></div><?php
}
@zarei-dev
zarei-dev / change_woocommerce_price.sql
Created September 24, 2021 20:32
woocommerce change price from rial to tooman
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_regular_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_sale_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_regular_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_sale_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_price_tmp' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_min_variation_price' AND meta_value != ''
UPDATE wp_postmeta SET meta_value = meta_value*.1 WHERE meta_key = '_max_variation_price' AND meta_value != ''