LLMS_Lesson_Handler::duplicate_meta( $post_id,  $new_post_id )


Source Source

File: includes/class.llms.lesson.handler.php

	public static function duplicate_meta( $post_id, $new_post_id ) {
		global $wpdb;

		// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
		// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared

		// Duplicate all post meta.
		$post_meta_infos = $wpdb->get_results( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id" );

		if ( count( $post_meta_infos ) != 0 ) {

			$sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";

			foreach ( $post_meta_infos as $meta_info ) {

				// Do not copy the following meta values.
				if ( '_llms_parent_section' === $meta_info->meta_key ) {
					$meta_info->meta_value = '';
				}
				if ( '_llms_parent_course' === $meta_info->meta_key ) {
					$meta_info->meta_value = '';
				}
				if ( '_prerequisite' === $meta_info->meta_key ) {
					$meta_info->meta_value = '';
				}
				if ( '_has_prerequisite' === $meta_info->meta_key ) {
					$meta_info->meta_value = '';
				}

				$meta_key        = $meta_info->meta_key;
				$meta_value      = addslashes( $meta_info->meta_value );
				$sql_query_sel[] = "SELECT $new_post_id, '$meta_key', '$meta_value'";

			}

			$sql_query       .= implode( ' UNION ALL ', $sql_query_sel );
			$insert_post_meta = $wpdb->query( $sql_query );

			return $insert_post_meta;
		}

		// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
		// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.