MFP > Deploy Show & Get Data

add_action(‘acf/save_post’, ‘add_show_children’); function add_show_children($post_id) { if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) return $post_id; if (!wp_is_post_revision($post_id) && ‘show’ == get_post_type($post_id) && ‘auto-draft’ != get_post_status($post_id) && ‘draft’ == get_post_status($post_id) ) { if (0 == get_post($post_id)->post_parent) { $countInt = (int) 1; $count = (string) $countInt;…Continue reading

ACF Do Shortcode Filter

add_filter(‘acf/format_value/type=text’, ‘acf_do_shortcode’, 10, 3); add_filter(‘acf/format_value/type=textarea’, ‘acf_do_shortcode’, 10, 3); function acf_do_shortcode($value, $post_id, $field) { if (is_admin()) { return $value; } return apply_filters(‘the_content’, $value); }Continue reading

MFP > get_email_data_from_options($key, $type)

function get_email_data_from_options($key, $type) { $values = array(); if (have_rows($key, ‘option’)) while (have_rows($key, ‘option’)) : the_row(); if (get_sub_field(‘type’) == $type) { $values[‘from_email’] = get_sub_field(‘from_email’); $values[‘from_name’] = get_sub_field(‘from_name’); $values[‘subject’] = strip_tags(apply_filters(‘the_content’, get_sub_field(‘subject’))); // $values[‘message’] = apply_filters(‘the_content’, get_sub_field(‘message’)); $values[‘message’] = get_sub_field(‘message’); add_filter(‘wp_mail_from’, function…Continue reading

PHP: Render User Gallery [user_gallery] V1

function render_user_gallery() { if (!is_user_logged_in()) { error_log(“[GALLERY] User not logged in.”); return ‘ You must be logged in to view your gallery. ‘; } // Retrieve user info and directories $current_user = wp_get_current_user(); $user_id = $current_user->ID; $upload_dir = wp_upload_dir(); $user_dir…Continue reading

TuterLMS User Enrolled Courses [Shortcode]

function display_user_enrolled_courses() { if (!is_user_logged_in()) { return “الرجاء تسجيل الدخول لرؤية دوراتك”; } if (!function_exists(‘tutor’)) { return “النظام غير متاح حاليًا”; } $user_id = get_current_user_id(); $enrolled_courses = tutor_utils()->get_enrolled_courses_by_user($user_id); if (empty($enrolled_courses)) { return “لم تشترك في أي دورة بعد”; } $output…Continue reading

PHP: Add key words

header(‘Content-Type: application/json’); function uploadImageToUploadsFolder() { if (isset($_FILES[‘image’]) && $_FILES[‘image’][‘error’] === UPLOAD_ERR_OK) { $image = $_FILES[‘image’]; $custom_tags = isset($_POST[‘tags’]) ? sanitize_text_field($_POST[‘tags’]) : ”; // Loguez le chemin temporaire pour vérifier où le fichier est initialement téléchargé error_log(‘Chemin temporaire du fichier :…Continue reading

hide html shop manager – 22nd April 2024

function hide_html_editor_for_shop_manager() { $user = wp_get_current_user(); if (in_array(‘shop_manager’, (array) $user->roles)) { echo ‘ ‘; } } add_action(‘admin_head’, ‘hide_html_editor_for_shop_manager’); function customize_shop_manager_role() { // Get the Shop Manager role object $role = get_role(‘shop_manager’); // Remove ‘publish’ capabilities for products $role->remove_cap(‘publish_products’); // Remove…Continue reading

Plural Category Names – Helper and Archive Display

function get_term_plural_name($term_id, $taxonomy = ‘category’) { $plural = get_term_meta($term_id, ‘plural_name’, true); return $plural ?: get_term($term_id, $taxonomy)>name; } add_filter(‘get_the_terms’, function ($terms, $post_id, $taxonomy) { if (is_archive() || is_home()) { // Only for list contexts foreach ($terms as $term) { $plural =…Continue reading

Smart convert images to webp (copy)

function convert_to_webp($file) { $file_path = $file[‘file’]; $file_type = $file[‘type’]; // Only for JPEG, PNG, and GIF images if (in_array($file_type, [‘image/jpeg’, ‘image/png’, ‘image/gif’, ‘image/jpg’])) { $webp_path = preg_replace(‘/.(jpe?g|png|gif)$/i’, ‘.webp’, $file_path); // Check if the GD library is available if (!function_exists(‘gd_info’)) {…Continue reading