Making WordPress.org

Changeset 10053


Ignore:
Timestamp:
07/10/2020 06:06:13 AM (5 years ago)
Author:
tellyworth
Message:

Plugin directory: send an email when plugin is added to the block directory.

See #5303

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-block-validator.php

    r10052 r10053  
    4141                            $terms = array_diff( $terms, array( 'block' ) );
    4242                        }
    43                         wp_set_object_terms( $post->ID, $terms, 'plugin_section' );
     43                        $result = wp_set_object_terms( $post->ID, $terms, 'plugin_section' );
     44                        if ( !is_wp_error( $result ) && !empty( $result ) ) {
     45                            if ( 'add' === $_POST['block-directory-edit'] ) {
     46                                Tools::audit_log( 'Plugin added to block directory.', $post->ID );
     47                                self::maybe_send_email_plugin_added( $post );
     48                            } elseif ( 'remove' === $_POST['block-directory-edit'] ) {
     49                                Tools::audit_log( 'Plugin removed from block directory.', $post->ID );
     50                            }
     51                        }
    4452                    }
    4553
     
    253261        }
    254262    }
     263
     264    /**
     265     * Sends an email confirmation to the plugin's author the first time a plugin is added to the directory.
     266     */
     267    protected static function maybe_send_email_plugin_added( $post ) {
     268
     269        $plugin_author = get_user_by( 'id', $post->post_author );
     270        if ( empty( $plugin_author ) )
     271            return false;
     272
     273        // Only send the email the first time it's added.
     274        if ( !add_post_meta( $post->ID, 'added_to_block_directory', time(), true ) )
     275            return false;
     276
     277
     278        /* translators: %s: plugin name */
     279        $email_subject = sprintf(
     280            __( '[WordPress Plugin Directory] Added to Block Directory - %s', 'wporg-plugins' ),
     281            $post->post_name
     282        );
     283
     284        /*
     285            Please leave the blank lines in place.
     286        */
     287        $email_content = sprintf(
     288            // translators: 1: plugin name, 2: plugin slug.
     289            __(
     290'This email is to let you know that your plugin %1$s has been added to the Block Directory here: https://wordpress.org/plugins/browse/block/.
     291
     292We\'re still working on improving Block Directory search and automated detection of blocks, so don\'t be alarmed if your block isn\'t immediately visible there. We\'ve built a new tool to help developers identify problems and potential improvements to block plugins, which you\'ll find here: https://wordpress.org/plugins/developers/block-plugin-validator/.
     293
     294In case you missed it, the Block Directory is a new feature coming to WordPress 5.5 in August. By having your plugin automatically added here, WordPress users will be able to discover your block plugin and install it directly from the editor when searching for blocks. If you have any feedback (bug, enhancement, etc) about this new feature, please open an issue here: https://github.com/wordpress/gutenberg/.
     295
     296If you would like your plugin removed from the Block Directory, you can do so here: https://wordpress.org/plugins/developers/block-plugin-validator/?plugin_url=%2$s
     297
     298Otherwise, you\'re all set!
     299
     300--
     301The WordPress Plugin Directory Team
     302https://make.wordpress.org/plugins', 'wporg-plugins'
     303            ),
     304            $post->post_title,
     305            $post->post_name
     306        );
     307
     308        $user_email = $plugin_author->user_email;
     309
     310        return wp_mail( $user_email, $email_subject, $email_content, 'From: plugins@wordpress.org' );
     311    }
    255312}
Note: See TracChangeset for help on using the changeset viewer.