wp_insert_comment

Definition:
function wp_insert_comment($commentdata) {}

Inserts a comment to the database.
The available comment data key names are ‘comment_author_IP’, ‘comment_date’, ‘comment_date_gmt’, ‘comment_parent’, ‘comment_approved’, and ‘user_id’.

Parameters

  • array $commentdata: Contains information on the comment.

Return values

returns:The new comment’s ID.

Defined actions

  • wp_insert_comment
    do_action('wp_insert_comment', $id, $comment);

Source code

function wp_insert_comment($commentdata) {

	global $wpdb;

	extract(stripslashes_deep($commentdata), EXTR_SKIP);



	if ( ! isset($comment_author_IP) )

		$comment_author_IP = '';

	if ( ! isset($comment_date) )

		$comment_date = current_time('mysql');

	if ( ! isset($comment_date_gmt) )

		$comment_date_gmt = get_gmt_from_date($comment_date);

	if ( ! isset($comment_parent) )

		$comment_parent = 0;

	if ( ! isset($comment_approved) )

		$comment_approved = 1;

	if ( ! isset($comment_karma) )

		$comment_karma = 0;

	if ( ! isset($user_id) )

		$user_id = 0;

	if ( ! isset($comment_type) )

		$comment_type = '';



	$data = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id');

	$wpdb->insert($wpdb->comments, $data);



	$id = (int) $wpdb->insert_id;



	if ( $comment_approved == 1 )

		wp_update_comment_count($comment_post_ID);



	$comment = get_comment($id);

	do_action('wp_insert_comment', $id, $comment);



	return $id;

}

3789

wp_insert_category

Definition:
function wp_insert_category($catarr, $wp_error = false) {}

Updates an existing Category or creates a new Category.

Parameters

  • mixed $catarr: See defaults below. Set ‘cat_ID’ to a non-zero value to update an existing category. The ‘taxonomy’ key was added in 3.0.0.
  • bool $wp_error: Optional, since 2.5.0. Set this to true if the caller handles WP_Error return values.

Return values

returns:ID number of the new or updated Category on success. Zero or a WP_Error on failure, depending on param $wp_error.

Source code

function wp_insert_category($catarr, $wp_error = false) {

	$cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');

	$catarr = wp_parse_args($catarr, $cat_defaults);

	extract($catarr, EXTR_SKIP);



	if ( trim( $cat_name ) == '' ) {

		if ( ! $wp_error )

			return 0;

		else

			return new WP_Error( 'cat_name', __('You did not enter a category name.') );

	}



	$cat_ID = (int) $cat_ID;



	// Are we updating or creating?

	if ( !empty ($cat_ID) )

		$update = true;

	else

		$update = false;



	$name = $cat_name;

	$description = $category_description;

	$slug = $category_nicename;

	$parent = $category_parent;



	$parent = (int) $parent;

	if ( $parent < 0 )

		$parent = 0;



	if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )

		$parent = 0;



	$args = compact('name', 'slug', 'parent', 'description');



	if ( $update )

		$cat_ID = wp_update_term($cat_ID, $taxonomy, $args);

	else

		$cat_ID = wp_insert_term($cat_name, $taxonomy, $args);



	if ( is_wp_error($cat_ID) ) {

		if ( $wp_error )

			return $cat_ID;

		else

			return 0;

	}



	return $cat_ID['term_id'];

}

3787

wp_insert_attachment

Definition:
function wp_insert_attachment($object, $file = false, $parent = 0) {}

Insert an attachment.
If you set the ‘ID’ in the $object parameter, it will mean that you are updating and attempt to update the attachment. You can also set the attachment name or title by setting the key ‘post_name’ or ‘post_title’.

Parameters

  • string|array $object: Arguments to override defaults.
  • string $file: Optional filename.
  • int $parent: Parent post ID.

Return values

returns:Attachment ID.

Defined actions

  • edit_attachment
    do_action('edit_attachment', $post_ID);
  • add_attachment
    do_action('add_attachment', $post_ID);

Source code

function wp_insert_attachment($object, $file = false, $parent = 0) {

	global $wpdb, $user_ID;



	$defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID,

		'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,

		'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',

		'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');



	$object = wp_parse_args($object, $defaults);

	if ( !empty($parent) )

		$object['post_parent'] = $parent;



	unset( $object[ 'filter' ] );



	$object = sanitize_post($object, 'db');



	// export array as variables

	extract($object, EXTR_SKIP);



	if ( empty($post_author) )

		$post_author = $user_ID;



	$post_type = 'attachment';



	if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )

		$post_status = 'inherit';



	// Make sure we set a valid category.

	if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) {

		// 'post' requires at least one category.

		if ( 'post' == $post_type )

			$post_category = array( get_option('default_category') );

		else

			$post_category = array();

	}



	// Are we updating or creating?

	if ( !empty($ID) ) {

		$update = true;

		$post_ID = (int) $ID;

	} else {

		$update = false;

		$post_ID = 0;

	}



	// Create a valid post name.

	if ( empty($post_name) )

		$post_name = sanitize_title($post_title);

	else

		$post_name = sanitize_title($post_name);



	// expected_slashed ($post_name)

	$post_name = wp_unique_post_slug($post_name, $post_ID, $post_status, $post_type, $post_parent);



	if ( empty($post_date) )

		$post_date = current_time('mysql');

	if ( empty($post_date_gmt) )

		$post_date_gmt = current_time('mysql', 1);



	if ( empty($post_modified) )

		$post_modified = $post_date;

	if ( empty($post_modified_gmt) )

		$post_modified_gmt = $post_date_gmt;



	if ( empty($comment_status) ) {

		if ( $update )

			$comment_status = 'closed';

		else

			$comment_status = get_option('default_comment_status');

	}

	if ( empty($ping_status) )

		$ping_status = get_option('default_ping_status');



	if ( isset($to_ping) )

		$to_ping = preg_replace('|\s+|', "\n", $to_ping);

	else

		$to_ping = '';



	if ( isset($post_parent) )

		$post_parent = (int) $post_parent;

	else

		$post_parent = 0;



	if ( isset($menu_order) )

		$menu_order = (int) $menu_order;

	else

		$menu_order = 0;



	if ( !isset($post_password) )

		$post_password = '';



	if ( ! isset($pinged) )

		$pinged = '';



	// expected_slashed (everything!)

	$data = compact( array( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' ) );

	$data = stripslashes_deep( $data );



	if ( $update ) {

		$wpdb->update( $wpdb->posts, $data, array( 'ID' => $post_ID ) );

	} else {

		// If there is a suggested ID, use it if not already present

		if ( !empty($import_id) ) {

			$import_id = (int) $import_id;

			if ( ! $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE ID = %d", $import_id) ) ) {

				$data['ID'] = $import_id;

			}

		}



		$wpdb->insert( $wpdb->posts, $data );

		$post_ID = (int) $wpdb->insert_id;

	}



	if ( empty($post_name) ) {

		$post_name = sanitize_title($post_title, $post_ID);

		$wpdb->update( $wpdb->posts, compact("post_name"), array( 'ID' => $post_ID ) );

	}



	wp_set_post_categories($post_ID, $post_category);



	if ( $file )

		update_attached_file( $post_ID, $file );



	clean_post_cache($post_ID);



	if ( ! empty( $context ) )

		add_post_meta( $post_ID, '_wp_attachment_context', $context, true );



	if ( $update) {

		do_action('edit_attachment', $post_ID);

	} else {

		do_action('add_attachment', $post_ID);

	}



	return $post_ID;

}

3785

wp_initial_nav_menu_meta_boxes

Definition:
function wp_initial_nav_menu_meta_boxes() {}

Limit the amount of meta boxes to just links, pages and cats for first time users.

Source code

function wp_initial_nav_menu_meta_boxes() {

	global $wp_meta_boxes;



	if ( get_user_option( 'metaboxhidden_nav-menus' ) !== false || ! is_array($wp_meta_boxes) )

		return;



	$initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-custom-links', 'add-page', 'add-category' );

	$hidden_meta_boxes = array();



	foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {

		foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {

			foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {

				if ( in_array( $box['id'], $initial_meta_boxes ) ) {

					unset( $box['id'] );

				} else {

					$hidden_meta_boxes[] = $box['id'];

				}

			}

		}

	}



	$user = wp_get_current_user();

	update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );

}

3783

wp_initial_constants

Definition:
function wp_initial_constants( ) {}

Defines initial WordPress constants

Source code

function wp_initial_constants( ) {

	global $blog_id;



	// set memory limits

	if ( !defined('WP_MEMORY_LIMIT') ) {

		if( is_multisite() ) {

			define('WP_MEMORY_LIMIT', '64M');

		} else {

			define('WP_MEMORY_LIMIT', '32M');

		}

	}



	if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {

		define( 'WP_MAX_MEMORY_LIMIT', '256M' );

	}



	/**

	 * The $blog_id global, which you can change in the config allows you to create a simple

	 * multiple blog installation using just one WordPress and changing $blog_id around.

	 *

	 * @global int $blog_id

	 * @since 2.0.0

	 */

	if ( ! isset($blog_id) )

		$blog_id = 1;



	// set memory limits.

	if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )

		@ini_set('memory_limit', WP_MEMORY_LIMIT);



	if ( !defined('WP_CONTENT_DIR') )

		define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down



	// Add define('WP_DEBUG', true); to wp-config.php to enable display of notices during development.

	if ( !defined('WP_DEBUG') )

		define( 'WP_DEBUG', false );



	// Add define('WP_DEBUG_DISPLAY', null); to wp-config.php use the globally configured setting for

	// display_errors and not force errors to be displayed. Use false to force display_errors off.

	if ( !defined('WP_DEBUG_DISPLAY') )

		define( 'WP_DEBUG_DISPLAY', true );



	// Add define('WP_DEBUG_LOG', true); to enable error logging to wp-content/debug.log.

	if ( !defined('WP_DEBUG_LOG') )

		define('WP_DEBUG_LOG', false);



	if ( !defined('WP_CACHE') )

		define('WP_CACHE', false);



	/**

	 * Private

	 */

	if ( !defined('MEDIA_TRASH') )

		define('MEDIA_TRASH', false);



	if ( !defined('SHORTINIT') )

		define('SHORTINIT', false);

}

3781