Create unique alphanumeric ID on wp_insert_post

See here the working version // function to save the randomString as custom field value function generate_AlphanumericID( $post_id ) { $postTypes = array(‘profile’, ‘article’); $postType = get_post_type( $post_id ); if (in_array( $postType, $postTypes ) ) { $characters = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ-_~’!,”; $charactersLength = strlen($characters); $randomString = ”; for ($i = 0; $i < 11; $i++) { $randomString … Read more

custom admin thumbnail for videos, not getting post’s id?

First, you don’t need the apply_filters below. That is called directly from the wp_mime_type_icon() function already. The issue is that your add_filter() call is missing the $accepted_args parameter. The add_filter() function has the following construct: add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) So the $accepted_args is 1 by default. Because of this, only the … Read more

Shortcode for a link and thumbnail

You are assigning the attachment URL to your $url variable: $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) ); then passing that same variable back to wp_get_attachment_url: return ‘<img src=”‘ . wp_get_attachment_url( $url ) . ‘”/><a href=”‘ . get_permalink( $id ) . ‘”>’ . get_the_title( $id ) . ‘</a>’; You should simply output it instead: return ‘<img … Read more

Transient unique names

Transients have practical limitation on key length (45 symbols or something like that), so using dynamic keys tends to come with risk of ending up with keys too long and having it break down. One of common practices is to form unique string (for example combination of plugin name and type of data being saved, … Read more

Add id to menu items in wp_nav_menu

Sounds like you would need to use a Custom Walker Function I’ve found some code on the WordPress Suport Forums which might be of some use: Walker Class – Pastebin class custom_nav_walker extends Walker_Nav_Menu { function start_el(&$output, $item, $depth, $args) { global $wp_query; $indent = ( $depth ) ? str_repeat( “\t”, $depth ) : ”; … Read more

Display site administrator’s id by current blog id inside link

If you want to construct for example: http://example.com/?ref=1,8,22 for multiple administrators of the current sub site, you can try the following (untested): $uids = get_users( array( ‘blog_id’ => get_current_blog_id(), ‘role’ => ‘administrator’, ‘fields’ => ‘ID’, ‘order_by’ => ‘ID’, ‘order’ => ‘ASC’, ) ); echo $url = add_query_arg( array( ‘ref’ => join( ‘,’, $uids ) ), … Read more

Generate unique number when registering a new user

This way would work … the user_register action is fired when the user is stored in the data base. You can add meta data to a user with add_metadata. add_action( ‘user_register’, ‘myplugin_registration_save’, 10, 1 ); function myplugin_registration_save( $user_id ) { add_metadata( $user_id, ‘unique_number’, date( ‘Y’ ).str_pad( $user_id, 4 ) ); }