Bardzo łatwo, po prostu użyj tego kodu:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: iWorks Random Post Slug | |
Plugin URI: http://iworks.pl/ | |
Description: Create random post slug. | |
Version: 1.0.0 | |
Author: Marcin Pietrzak | |
Author URI: http://iworks.pl/ | |
License: GPLv2 or later | |
License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
class iWorks_Random_Post_Slug { | |
private $length = 10; | |
private $semaphore = '_iworks_random_slug'; | |
public function __construct() { | |
add_action( 'publish_post', array( $this, 'action_publish_post_add_random_slug' ), 10, 3 ); | |
} | |
public function action_publish_post_add_random_slug( $post_id, $post, $old_status ) { | |
if ( get_post_meta( $post_id, $this->semaphore, true ) ) { | |
return; | |
} | |
add_post_meta( $post_id, $this->semaphore, 'set', true ); | |
$postarr = array( | |
'ID' => $post_id, | |
'post_name' => wp_generate_password( $this->length, false, false ), | |
); | |
wp_update_post( $postarr ); | |
} | |
} | |
new iWorks_Random_Post_Slug; |