Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@mehrshaddarzi
mehrshaddarzi / no_cache_header.php
Created July 20, 2025 08:56
No Cache Header in WordPress
<?php
/**
* افزودن هدرهای عدم کش برای صفحات حاوی 'rahkaran' در URL
*/
add_filter('nocache_headers_args', 'rahkaran_no_cache_headers_with_cloudflare');
function rahkaran_no_cache_headers_with_cloudflare($headers) {
// بررسی وجود 'rahkaran' در URL بدون توجه به بزرگی/کوچکی حروف
if (isset($_SERVER['REQUEST_URI']) {
$request_uri = strtolower($_SERVER['REQUEST_URI']);
@mehrshaddarzi
mehrshaddarzi / WooCommerceReportPage.php
Created July 16, 2025 11:18
Create New Report Page WooCommerce By Select Box "woocommerce-checkout-field-editor-pro" plugin
<?php
class Advanced_WC_Report {
public function __construct() {
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('admin_head', array($this, 'add_admin_styles'));
}
@mehrshaddarzi
mehrshaddarzi / category.md
Created June 29, 2025 06:15
Elementor Dynamic Tags
ثابت (Constant) توضیح و کاربرد مثال ویجت‌ها
Module::TEXT_CATEGORY برای خروجی‌های متنی ساده. این پرکاربردترین دسته است. ویرایشگر متن، سربرگ، دکمه، نقل قول
Module::URL_CATEGORY برای هر نوع لینک و URL. فیلد "پیوند" در ویجت‌های دکمه، تصویر، سربرگ
Module::IMAGE_CATEGORY برای خروجی تصویر. خروجی باید آرایه‌ای با کلید id و url باشد. ویجت تصویر، پس‌زمینه بخش/ستون
Module::NUMBER_CATEGORY برای خروجی‌های عددی. مانند قیمت، تعداد، شناسه و... ویجت شمارنده، جدول قیمت، سربرگ
Module::COLOR_CATEGORY برای خروجی کد رنگ. (مثلاً #ff5500) کنترل‌های انتخاب رنگ در بخش استایل

| ثابت (Constant) | توضیح و کاربرد | مثال ویجت‌ها |

@mehrshaddarzi
mehrshaddarzi / elementor_show_hide.php
Last active July 25, 2025 10:21
elementor Add condition show/hide field
<?php
/**
* Register custom Elementor display conditions.
*
* @param \Elementor\Core\Kits\Documents\Tabs\Conditions_Manager $conditions_manager
* @return void
*/
function register_custom_elementor_conditions( $conditions_manager ) {
@mehrshaddarzi
mehrshaddarzi / elementor_font_color.php
Created June 25, 2025 10:33
Add Default Global font and Color in Eleemntor plugin when new Active Theme
<?php
function set_elementor_global_colors_once() {
if ( ! get_option('my_theme_elementor_colors_set') ) {
$global_settings = \Elementor\Plugin::$instance->kits_manager->get_active_kit();
$global_settings->set_settings([
'system_colors' => [
'primary-color' => [
'title' => __('Primary Color', 'your-textdomain'),
'color' => '#1e73be',
@mehrshaddarzi
mehrshaddarzi / add_dynamic_field.php
Created June 25, 2025 06:18
elemntor_widget.php
<?php
use Elementor\Core\DynamicTags\Tag;
class Custom_Meta_Fields_Tag extends \Elementor\Core\DynamicTags\Tag {
public function get_name() {
return 'custom-meta-fields';
}
@mehrshaddarzi
mehrshaddarzi / elementor_controller.php
Created June 25, 2025 06:13
New controller in elementor with php
<?php
// document
https://developers.elementor.com/docs/controls/
// Define
use Elementor\Base_Data_Control;
class My_Select2_Control extends Base_Data_Control {
public function get_type() {
@mehrshaddarzi
mehrshaddarzi / filter_current_post_meta.php
Last active July 25, 2025 10:38
Dynamic tags in elementor with php
<?php
add_filter( 'elementor/dynamic_tags/tag_value', function( $value, $tag ) {
// بررسی اینکه آیا تگ مورد نظر "custom field" هست
if ( $tag->get_name() === 'post-custom-field' ) {
// گرفتن post ID فعلی
$post_id = get_the_ID();
@mehrshaddarzi
mehrshaddarzi / permalink.php
Created May 15, 2025 08:52
add Post Id before Custom Post Type Slug in WordPress
@mehrshaddarzi
mehrshaddarzi / wordpress_session_time.php
Created May 14, 2025 06:23
WordPress User Auth cookie and Session Time
<?php
// Change Session Auth Cookie
add_filter('auth_cookie_expiration', 'filter_auth_cookie_expiration', 99, 3);
function filter_auth_cookie_expiration($seconds, $user_id, $remember){
$user = get_userdata($user_id);
if ( in_array( 'customer', (array) $user->roles ) || in_array( 'subscriber', (array) $user->roles ) ) {
return $seconds;
}