Skip to content

Commit

Permalink
Merge pull request #13 from alleyinteractive/hire-prompt
Browse files Browse the repository at this point in the history
Adding a hiring prompt
  • Loading branch information
srtfisher authored Jul 9, 2021
2 parents 8a88734 + d90928f commit 170f200
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 3 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<arg value="ps" />
<exclude-pattern>tests/</exclude-pattern>

<rule ref="Alley-Interactive" />
<rule ref="Alley-Interactive">
<exclude name="WordPress.WP.AlternativeFunctions" />
</rule>
</ruleset>
43 changes: 42 additions & 1 deletion src/class-install-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ protected function execute( InputInterface $input, OutputInterface $output ): in
|_| |_|\__,_|_| |_|\__|_|\___|</> \n\n"
);

if ( $this->check_if_hiring() ) {
$output->write(
"Alley is hiring! Apply today at <href=https://alley.co/careers/>https://alley.co/careers/</>. \n\n"
);
}

// Determine if we're in a WordPress project already.
$wordpress_root = $this->get_wordpress_root( $input, $output );

Expand Down Expand Up @@ -127,7 +133,7 @@ protected function get_wordpress_root( InputInterface $input, OutputInterface $o
null,
/**
* Callback function that handles validating the manually defined WordPress installation directory.
*
*
* @param string $dir The full path to the WordPress directory, as defined by the user.
* @return string $dir The path as passed by the user, after passing validation.
*/
Expand Down Expand Up @@ -340,4 +346,39 @@ protected function get_mu_plugin_loader( string $plugin_name ): string {
}
EOT;
}

/**
* Check if Alley is hiring and throw a prompt.
*
* @return boolean
*/
protected function check_if_hiring(): bool {
try {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://careers.alley.co/wp-json/wp/v2/job/' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 3 );

$feed = json_decode( curl_exec( $ch ), true );

curl_close( $ch );
} catch ( \Throwable $e ) {
return false;
}

if ( empty( $feed ) ) {
return false;
}

// Check if there is a developer posting in the feed.
foreach ( $feed as $posting ) {
$title = strtolower( $posting['title']['rendered'] ?? '' );

if ( false !== strpos( $title, 'developer' ) ) {
return true;
}
}

return false;
}
}

0 comments on commit 170f200

Please sign in to comment.