Making WordPress.org

Changeset 11842


Ignore:
Timestamp:
05/13/2022 04:45:59 PM (4 years ago)
Author:
iandunn
Message:

Profiles: Apply coding standards.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-profiles-wp-activity-notifier/wporg-profiles-wp-activity-notifier.php

    r10663 r11842  
    88
    99class WPOrg_WP_Activity_Notifier {
    10 
    1110        private $activity_handler_url = 'https://profiles.wordpress.org/wp-admin/admin-ajax.php';
    1211
     
    1918         * Returns always the same instance of this plugin.
    2019         *
    21          * @return Plugin
     20         * @return WPOrg_WP_Activity_Notifier
    2221         */
    2322        public static function get_instance() {
     
    2524                        self::$instance = new self();
    2625                }
     26
    2727                return self::$instance;
    2828        }
     
    6262         *
    6363         * @param WP_Post $post The post
     64         *
    6465         * @return boolean True == the post can be notified about.
    6566         */
    6667        public function is_post_notifiable( $post ) {
    67 
    6868                // Sanity check the argument is a post
    69                 if ( ! $post || ! is_a( $post, 'WP_Post' ) )
     69                if ( ! $post || ! is_a( $post, 'WP_Post' ) ) {
    7070                        return false;
     71                }
    7172
    7273                // Don't notify if the site is for subscribers only
    73                 if ( class_exists( 'Subscribers_Only' ) )
     74                if ( class_exists( 'Subscribers_Only' ) ) {
    7475                        $notifiable = false;
     76                }
    7577
    7678                // Don't notify if not of 'post' post_type
    77                 elseif ( 'post' != $post->post_type )
     79                elseif ( 'post' != $post->post_type ) {
    7880                        $notifiable = false;
     81                }
    7982
    8083                // Don't notify if not publicly published
    81                 elseif ( 'publish' != $post->post_status )
     84                elseif ( 'publish' != $post->post_status ) {
    8285                        $notifiable = false;
     86                }
    8387
    8488                // Don't notify if password is required
    85                 elseif ( ! empty( $post->post_password ) )
     89                elseif ( ! empty( $post->post_password ) ) {
    8690                        $notifiable = false;
     91                }
    8792
    8893                // At this point it is permitted to notify about the post
    89                 else
     94                else {
    9095                        $notifiable = true;
     96                }
    9197
    9298                // Return filtered value to allow overriding or extending checks
    9399                return apply_filters( 'wporg_profiles_wp_activity-is_post_notifiable', $notifiable, $post );
    94 
    95100        }
    96101
     
    98103         * Only send notification for post getting published.
    99104         *
    100          * @param string $new_status The new status for the post
    101          * @param string $old_status The old status for the post
     105         * @param string  $new_status The new status for the post
     106         * @param string  $old_status The old status for the post
    102107         * @param WP_Post $post The post
    103108         */
    104109        public function maybe_notify_new_published_post( $new_status, $old_status, $post ) {
    105 
    106110                // Only proceed if the post is transitioning to the publish status
    107                 if ( 'publish' != $new_status )
    108                         return;
     111                if ( 'publish' != $new_status ) {
     112                        return;
     113                }
    109114
    110115                // Only proceed if the post is actually changing status
    111                 if ( $old_status == $new_status )
    112                         return;
     116                if ( $old_status == $new_status ) {
     117                        return;
     118                }
    113119
    114120                // Only proceed if permitted to notify about the post
    115                 if ( ! $this->is_post_notifiable( $post ) )
    116                         return;
     121                if ( ! $this->is_post_notifiable( $post ) ) {
     122                        return;
     123                }
    117124
    118125                // Send notification for the post
     
    149156                                'content'  => $content,
    150157                                'url'      => get_permalink( $post->ID ),
    151                         )
     158                        ),
    152159                );
    153160
     
    158165         * Handler for comment creation.
    159166         *
    160          * @param int $id         Comment ID
    161          * @param object $comment Comment
    162          * @return void
    163         */
     167         * @param int        $id      Comment ID
     168         * @param WP_Comment $comment Comment
     169         */
    164170        function insert_comment( $id, $comment ) {
    165                 if ( 1 == $comment->comment_approved )
     171                if ( 1 == $comment->comment_approved ) {
    166172                        $this->maybe_notify_new_approved_comment( 'approved', '', $comment );
     173                }
    167174        }
    168175
     
    170177         * Only send notification for comment getting published on a public post.
    171178         *
    172          * @param string $new_status The new status for the comment
    173          * @param string $old_status The old status for the comment
     179         * @param string     $new_status The new status for the comment
     180         * @param string     $old_status The old status for the comment
     181         * @param WP_Comment $comment    The comment
     182         */
     183        public function maybe_notify_new_approved_comment( $new_status, $old_status, $comment ) {
     184                // Only proceed if the comment is transitioning to the approved status
     185                if ( 'approved' != $new_status ) {
     186                        return;
     187                }
     188
     189                $post = get_post( $comment->comment_post_ID );
     190
     191                // Only proceed if permitted to notify about the post
     192                if ( ! $this->is_post_notifiable( $post ) ) {
     193                        return;
     194                }
     195
     196                // Only proceed if there are no objections to the comment notification
     197                if ( apply_filters( 'wporg_profiles_wp_activity-is_comment_notifiable', true, $comment, $post ) ) {
     198                        $this->notify_new_approved_comment( $comment, $post );
     199                }
     200        }
     201
     202        /**
     203         * Sends activity notification for new comment.
     204         *
    174205         * @param WP_Comment $comment The comment
    175          */
    176         public function maybe_notify_new_approved_comment( $new_status, $old_status, $comment ) {
    177 
    178                 // Only proceed if the comment is transitioning to the approved status
    179                 if ( 'approved' != $new_status )
    180                         return;
    181 
    182                 $post = get_post( $comment->comment_post_ID );
    183 
    184                 // Only proceed if permitted to notify about the post
    185                 if ( ! $this->is_post_notifiable( $post ) )
    186                         return;
    187 
    188                 // Only proceed if there are no objections to the comment notification
    189                 if ( apply_filters( 'wporg_profiles_wp_activity-is_comment_notifiable', true, $comment, $post ) )
    190                         $this->notify_new_approved_comment( $comment, $post );
    191         }
    192 
    193         /**
    194          * Sends activity notification for new comment.
    195          *
    196          * @param WP_Comment $comment The comment
    197          * @param WP_Post $post The comment's post
     206         * @param WP_Post    $post The comment's post
    198207         */
    199208        private function notify_new_approved_comment( $comment, $post ) {
     
    203212                }
    204213
    205                 if ( ! $comment->user_id )
    206                         return;
    207 
    208                 if ( ! $user = get_user_by( 'id', $comment->user_id ) )
    209                         return;
     214                if ( ! $comment->user_id ) {
     215                        return;
     216                }
     217
     218                if ( ! $user = get_user_by( 'id', $comment->user_id ) ) {
     219                        return;
     220                }
    210221
    211222                $args = array(
     
    220231                                'blog_url'   => site_url(),
    221232                                'url'        => get_comment_link( $comment ),
    222                         )
     233                        ),
    223234                );
    224235
     
    235246         */
    236247        private function _notify_forum_topic_payload( $activity, $topic_id ) {
    237 
    238248                // Don't notify if importing.
    239249                if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
     
    258268                $url = bbp_get_topic_permalink( $topic_id );
    259269                // Remove moderator flags
    260                 $url = remove_query_arg( [ 'view' ], $url );
     270                $url = remove_query_arg( array( 'view' ), $url );
    261271
    262272                $args = array(
     
    274284                                'site'      => get_bloginfo( 'name' ),
    275285                                'site_url'  => site_url(),
    276                         )
     286                        ),
    277287                );
    278288
     
    307317         */
    308318        private function _notify_forum_reply_payload( $activity, $reply_id ) {
    309 
    310319                // Don't notify if importing.
    311320                if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
     
    330339                $url = bbp_get_reply_url( $reply_id );
    331340                // Remove moderator flags
    332                 $url = remove_query_arg( [ 'view' ], $url );
     341                $url = remove_query_arg( array( 'view' ), $url );
    333342
    334343                $args = array(
     
    346355                                'site'      => get_bloginfo( 'name' ),
    347356                                'site_url'  => site_url(),
    348                         )
     357                        ),
    349358                );
    350359
    351360                wp_remote_post( $this->activity_handler_url, $args );
    352 
    353361        }
    354362
     
    381389         * @param int $reply_id Optional. The reply id.
    382390         * @param int $words    Optional. The number of words for the excerpt. Default 15.
     391         *
    383392         * @return string
    384393         */
     
    401410         * @param int    $length     Optional. The number of words or characters to try down to. Default 15.
    402411         * @param string $trim_style Optional. The manner in which the text should be trimmed. Either 'chars' or 'words'. Default 'words'.
     412         *
    403413         * @return string
    404414         */
     
    419429
    420430                // If trimming by chars, behave like a more multibyte-aware
    421                 // bbp_get_reply_excerp().
     431                // /* bbp_get_reply_excerpt */().
    422432                if ( 'chars' === $trim_style ) {
    423433                        // Multibyte support
     
    437447                        }
    438448                }
     449
    439450                // Else trim by words.
    440451                else {
     
    444455                return $text;
    445456        }
    446 
    447457}
    448458
Note: See TracChangeset for help on using the changeset viewer.