public function start_bypass_clone() { check_ajax_referer('llms_performance_nonce', 'nonce'); if (!current_user_can('manage_lifterlms')) { wp_die('Permisiuni insuficiente'); } $start_time = microtime(true); $course_id = intval($_POST['course_id']); try { global $wpdb; // STEP 1: Obține datele originale $original_course = get_post($course_id); if (!$original_course || $original_course->post_type !== 'course') { throw new Exception('Cursul original nu există'); } // STEP 2: CLONARE DIRECTĂ ÎN BAZA DE DATE (fără hook-uri!) - O SINGURĂ DATĂ! // Clonează cursul principal direct în DB $new_course_id = $wpdb->insert( $wpdb->posts, array( 'post_title' => $original_course->post_title . ' - Bypass Clone', 'post_content' => $original_course->post_content, 'post_excerpt' => $original_course->post_excerpt, 'post_status' => 'draft', 'post_type' => 'course', 'post_parent' => 0, 'post_author' => get_current_user_id(), 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1), 'comment_status' => $original_course->comment_status, 'ping_status' => $original_course->ping_status, 'post_name' => '', 'to_ping' => '', 'pinged' => '', 'post_modified' => current_time('mysql'), 'post_modified_gmt' => current_time('mysql', 1), 'post_content_filtered' => '', 'menu_order' => $original_course->menu_order, 'guid' => '' ) ); if (!$new_course_id) { throw new Exception('Eroare la inserarea cursului în DB'); } $new_course_id = $wpdb->insert_id; // Copiază metadata cursului direct în DB $wpdb->query($wpdb->prepare( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) SELECT %d, meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d", $new_course_id, $course_id )); // STEP 3: Folosește API-ul nativ LifterLMS pentru clonare (CRUCIAL!) if (function_exists('llms_get_post')) { $llms_course = llms_get_post($course_id); if ($llms_course) { // Obține secțiunile prin API-ul LifterLMS $sections = $llms_course->get_sections(); $lessons = $llms_course->get_lessons(); $lessons_cloned = 0; $sections_cloned = 0; // STEP 4: Clonează secțiunile folosind API-ul LifterLMS $section_map = array(); // Mapare ID-uri vechi -> noi foreach ($sections as $section) { $section_data = array( 'post_title' => $section->get('title'), 'post_content' => $section->get('content'), 'post_status' => 'publish', 'post_type' => 'section', 'post_author' => get_current_user_id(), 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1), 'menu_order' => $section->get('order') ); $new_section_id = wp_insert_post($section_data); if ($new_section_id) { // Copiază toate meta-urile secției $original_meta = get_post_meta($section->get('id')); foreach ($original_meta as $key => $values) { foreach ($values as $value) { add_post_meta($new_section_id, $key, maybe_unserialize($value)); } } // Setează parent course pentru secțiune update_post_meta($new_section_id, '_llms_parent_course', $new_course_id); $section_map[$section->get('id')] = $new_section_id; $sections_cloned++; } } // STEP 5: Clonează lecțiile folosind API-ul LifterLMS foreach ($lessons as $lesson) { $lesson_data = array( 'post_title' => $lesson->get('title'), 'post_content' => $lesson->get('content'), 'post_excerpt' => $lesson->get('excerpt'), 'post_status' => 'publish', 'post_type' => 'lesson', 'post_author' => get_current_user_id(), 'post_date' => current_time('mysql'), 'post_date_gmt' => current_time('mysql', 1), 'menu_order' => $lesson->get('order') ); $new_lesson_id = wp_insert_post($lesson_data); if ($new_lesson_id) { // Copiază toate meta-urile lecției $original_meta = get_post_meta($lesson->get('id')); foreach ($original_meta as $key => $values) { foreach ($values as $value) { add_post_meta($new_lesson_id, $key, maybe_unserialize($value)); } } // Setează relațiile LifterLMS update_post_meta($new_lesson_id, '_llms_parent_course', $new_course_id); // Setează parent section dacă există $original_section_id = $lesson->get('parent_section'); if ($original_section_id && isset($section_map[$original_section_id])) { update_post_meta($new_lesson_id, '_llms_parent_section', $section_map[$original_section_id]); } $lessons_cloned++; } } // STEP 6: Actualizează structura cursului LifterLMS (CRUCIAL!) if (method_exists($llms_course, 'get_syllabus')) { $syllabus = $llms_course->get_syllabus(); if ($syllabus) { // Copiază structura syllabus pentru noul curs update_post_meta($new_course_id, '_llms_syllabus', $syllabus); } } // Forțează regenerarea cache-ului LifterLMS pentru noul curs if (function_exists('llms_get_post')) { $new_llms_course = llms_get_post($new_course_id); if ($new_llms_course && method_exists($new_llms_course, 'get_sections')) { $new_llms_course->get_sections(); // Forțează regenerarea } } } else { throw new Exception('Nu s-a putut încărca cursul cu API-ul LifterLMS'); } } else { throw new Exception('API-ul LifterLMS nu este disponibil'); } // STEP 7: Cleanup și finalizare $wpdb->update( $wpdb->posts, array('guid' => home_url('/?p=' . $new_course_id)), array('ID' => $new_course_id) ); // Invalidează cache-ul minimal necesar wp_cache_delete($new_course_id, 'posts'); clean_post_cache($new_course_id); $total_time = microtime(true) - $start_time; wp_send_json_success(array( 'new_title' => $original_course->post_title . ' - Bypass Clone', 'lessons_cloned' => $lessons_cloned, 'sections_cloned' => $sections_cloned, 'execution_time' => $total_time, 'edit_url' => admin_url('post.php?post=' . $new_course_id . '&action=edit') )); } catch (Exception $e) { wp_send_json_error('Eroare bypass: ' . $e->getMessage()); } } Autentificare ‹ Master Training —

Autentificare

Go to /index.php

Prove your humanity: 9   +   2   =  

← Mergi la Master Training