| 318 | * Check if a plugin with the provided slug already exists. |
| 319 | * |
| 320 | * Runs on 'wp_insert_post_data' when editing a plugin on Edit Plugin screen. |
| 321 | * |
| 322 | * @param array $data The data to be inserted into the database. |
| 323 | * @param array $postarr The raw data passed to `wp_insert_post()`. |
| 324 | * @return array The data to insert into the database. |
| 325 | */ |
| 326 | function check_existing_plugin_slug_on_post_update( $data, $postarr ) { |
| 327 | if ( 'plugin' !== $data['post_type'] || ! isset( $postarr['ID'] ) ) { |
| 328 | return $data; |
| 329 | } |
| 330 | |
| 331 | $existing_plugin = Plugin_Directory\Plugin_Directory::get_plugin_post( $data['post_name'] ); |
| 332 | |
| 333 | // Is there already a plugin with the same slug? |
| 334 | if ( $existing_plugin && $existing_plugin->ID != $postarr['ID'] ) { |
| 335 | wp_die( sprintf( |
| 336 | /* translators: %s: plugin slug */ |
| 337 | __( 'Error: The plugin %s already exists.', 'wporg-plugins' ), |
| 338 | $data['post_name'] |
| 339 | ) ); |
| 340 | } |
| 341 | |
| 342 | return $data; |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Check if a plugin with the provided slug already exists. |
| 347 | * |
| 348 | * Runs on 'wp_unique_post_slug' when editing a plugin via Quick Edit. |
| 349 | * |
| 350 | * @param string $slug The unique post slug. |
| 351 | * @param int $post_ID Post ID. |
| 352 | * @param string $post_status Post status. |
| 353 | * @param string $post_type Post type. |
| 354 | * @param int $post_parent Post parent ID. |
| 355 | * @param string $original_slug The original post slug. |
| 356 | * @return string The unique post slug. |
| 357 | */ |
| 358 | function check_existing_plugin_slug_on_inline_save( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { |
| 359 | if ( 'plugin' !== $post_type ) { |
| 360 | return $slug; |
| 361 | } |
| 362 | |
| 363 | // Did wp_unique_post_slug() change the slug to avoid a conflict? |
| 364 | if ( $slug !== $original_slug ) { |
| 365 | wp_die( sprintf( |
| 366 | /* translators: %s: plugin slug */ |
| 367 | __( 'Error: The plugin %s already exists.', 'wporg-plugins' ), |
| 368 | $original_slug |
| 369 | ) ); |
| 370 | } |
| 371 | |
| 372 | return $slug; |
| 373 | } |
| 374 | |
| 375 | /** |