• LifterLMS
  • Knowledge Base
  • Academy
  • Blog
  • Podcast
  • Contributors
  • My Account

LifterLMS LifterLMS

  • Code Reference
  • REST API
  • LLMS-CLI

Code Reference

Skip to content
Filter by type:
Search
Browse: Home / Code Reference / Functions / llms_update_user_postmeta()

llms_update_user_postmeta( int $user_id, int $post_id, string $meta_key, mixed $meta_value, bool $unique = true )

Update user postmeta data.

Contents

  • Parameters
  • Return
  • Source
  • Related
    • Uses
    • Used By
  • Changelog
  • User Contributed Notes

Parameters #Parameters

$user_id

(int) (Required) WP User ID.

$post_id

(int) (Required) WP Post ID.

$meta_key

(string) (Required) Meta key.

$meta_value

(mixed) (Required) Meta value (don't serialize serializable values).

$unique

(bool) (Optional) If true, updates existing value (if it exists). If false, will add a new record (allowing multiple records with the same key to exist). Deafult true.

Default value: true


Top ↑

Return #Return

(bool)


Top ↑

Source #Source

File: includes/functions/llms.functions.user.postmeta.php

	function llms_update_user_postmeta( $user_id, $post_id, $meta_key, $meta_value, $unique = true ) {

		$item = false;

		// if unique is true, make an update to the existing item (if it exists).
		if ( $unique ) {

			// locate the item.
			$existing = _llms_query_user_postmeta( $user_id, $post_id, $meta_key );
			if ( $existing ) {

				// load it and make sure it exists.
				$item = new LLMS_User_Postmeta( $existing[0]->meta_id, false );
				if ( ! $item->exists() ) {
					$item = false;
				}
			}
		}

		if ( ! $item ) {
			$item = new LLMS_User_Postmeta();
		}

		// setup the data we want to store.
		$updated_date = llms_current_time( 'mysql' );
		$meta_value   = maybe_serialize( $meta_value );
		$item->setup( compact( 'user_id', 'post_id', 'meta_key', 'meta_value', 'updated_date' ) );
		return $item->save();

	}

Expand full source code Collapse full source code View on GitHub


Top ↑

Related #Related

Uses #Uses

Uses
Uses Description
includes/models/model.llms.user.postmeta.php: LLMS_User_Postmeta::__construct()

Constructor

includes/functions/llms-functions-wrappers.php: llms_current_time()

Retrieve the current time based on specified type.

includes/functions/llms.functions.user.postmeta.php: _llms_query_user_postmeta()

Query user postmeta data.

Top ↑

Used By #Used By

Used By
Used By Description
includes/class-llms-engagement-handler.php: LLMS_Engagement_Handler::handle_email()

Send an email engagement

includes/class-llms-engagement-handler.php: LLMS_Engagement_Handler::create_actions()

Runs post-creation actions when creating/awarding an achievement or certificate to a user.

includes/models/model.llms.student.php: LLMS_Student::insert_status_postmeta()

Add a new status record to the user postmeta table for a specific product

includes/functions/llms.functions.user.postmeta.php: llms_bulk_update_user_postmeta()

Update bulk update user postmeta data.


Top ↑

Changelog #Changelog

Changelog
Version Description
3.21.0 Introduced.

Top ↑

User Contributed Notes #User Contributed Notes

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

© 2014 - 2023 LifterLMS · Privacy Policy · Terms and Conditions

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.