Making WordPress.org

Changeset 11761


Ignore:
Timestamp:
04/11/2022 09:01:21 PM (4 years ago)
Author:
iandunn
Message:

Slack: Return results instead of echoing for testability.

Location:
sites/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/api.wordpress.org/public_html/dotorg/slack/props.php

    r2155 r11761  
    11<?php
     2
     3/*
     4 * This endpoint receives payloads from the `/props` slash command in `#props`.
     5 *
     6 * To manage, browse to https://wordpress.slack.com/apps/manage/custom-integrations > Slash Commands > `/props`.
     7 */
    28
    39namespace {
     
    2834
    2935if ( constant( __NAMESPACE__ . '\\WEBHOOK_TOKEN' ) === $_POST['token'] ) {
    30         run( $_POST );
     36        echo run( $_POST );
    3137}
    32 
    3338}
  • sites/trunk/common/includes/slack/props/lib.php

    r10878 r11761  
    55
    66function show_error( $user ) {
    7         echo "Please use `/props SLACK_USERNAME MESSAGE` to give props.\n";
     7        return "Please use `/props SLACK_USERNAME MESSAGE` to give props.\n";
    88}
    99
     10/**
     11 * Receive `/props` request and send to `#props`.
     12 *
     13 * @param array $data
     14 * @param bool  $force_test Send to test channel instead of #props
     15 *
     16 * @return string
     17 */
    1018function run( $data, $force_test = false ) {
    1119        $sender = $data['user_name'];
    1220
    1321        if ( $data['command'] !== '/props' ) {
    14                 echo "???\n";
    15                 return;
     22                return "???\n";
    1623        }
    1724
    1825        if ( empty( $data['text'] ) ) {
    19                 show_error( $sender );
    20                 return;
     26                return show_error( $sender );
    2127        }
    2228
     
    2632
    2733        if ( ! strlen( $receiver ) || ! strlen( $message ) ) {
    28                 show_error( $sender );
    29                 return;
     34                return show_error( $sender );
    3035        }
    3136
     
    4348                $send->set_icon( call_user_func( $get_avatar, $sender, $data['user_id'], $data['team_id'] ) );
    4449        }
    45        
     50
    4651        if ( $force_test ) {
    4752                $send->testing( true );
     
    5055        $send->send( '#props' );
    5156
    52         printf( "Your props to @%s have been sent.\n", $receiver );
     57        return sprintf( "Your props to @%s have been sent.\n", $receiver );
    5358}
  • sites/trunk/common/includes/slack/props/test.php

    r2154 r11761  
    2323);
    2424
    25 run( $data, true );
     25echo run( $data, true );
Note: See TracChangeset for help on using the changeset viewer.