Skip to content

Instantly share code, notes, and snippets.

View mehrshaddarzi's full-sized avatar

Mehrshad Darzi mehrshaddarzi

View GitHub Profile
@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 June 28, 2025 14:25
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 June 25, 2025 06:02
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;
}
@mehrshaddarzi
mehrshaddarzi / delete_order_note_woocommerce.php
Created May 14, 2025 06:05
Delete Order Note For completed WooCommerce
<?php
// Setup CronJob
//add_action('plugins_loaded', 'add_custom_wc_cron_job_note_completed', 70);
function add_custom_wc_cron_job_note_completed()
{
if (!wp_next_scheduled('delete_order_notes_completed')) {
wp_schedule_event(time(), 'daily', 'delete_order_notes_completed');
}
}
@mehrshaddarzi
mehrshaddarzi / woodmat_css_post_class.php
Created May 14, 2025 05:56
Woodmart Css Post class
<?php
// Remove Image Classes
// using function to add class to `the_post_thumbnail()`
// https://wordpress.stackexchange.com/questions/102158/add-class-name-to-post-thumbnail
add_filter('wp_get_attachment_image_attributes','filter_the_post_thumbnail_remove_class');
function filter_the_post_thumbnail_remove_class($attr) {
if(is_admin() || wp_doing_ajax()) {
return $attr;