This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from Automattic/fix/254/allow_jpcrm_versions
Resolves #254 - allow custom JPCRM builds/versions
- Loading branch information
Showing
6 changed files
with
182 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
/** | ||
* CRM for everyone. | ||
* | ||
* @package jurassic-ninja | ||
*/ | ||
|
||
namespace jn; | ||
|
||
add_action( | ||
'jurassic_ninja_init', | ||
function () { | ||
|
||
$defaults = array( | ||
'jpcrm' => false, | ||
'jpcrm-build' => false, | ||
'jpcrm-version' => false, | ||
); | ||
|
||
add_action( | ||
'jurassic_ninja_add_features_before_auto_login', | ||
function ( &$app, $features, $domain ) use ( $defaults ) { | ||
|
||
$features = array_merge( $defaults, $features ); | ||
|
||
// Don't install if Jetpack CRM isn't selected. | ||
if ( ! $features['jpcrm'] ) { | ||
return; | ||
} | ||
|
||
if ( $features['jpcrm-version'] ) { | ||
|
||
// Install specified version of Jetpack CRM from WP.org repo. | ||
debug( '%s: Installing Jetpack CRM version %s from WP.org repo', $domain, $features['jpcrm-version'] ); | ||
add_jpcrm_from_wporg( $features['jpcrm-version'] ); | ||
|
||
} elseif ( $features['jpcrm-build'] ) { | ||
|
||
// Install custom build of Jetpack CRM. | ||
debug( '%s: Installing Jetpack CRM from %s', $domain, $features['jpcrm-build'] ); | ||
add_jpcrm_from_custom_build( $features['jpcrm-build'] ); | ||
|
||
} else { | ||
|
||
// Install current version of Jetpack CRM from WP.org repo. | ||
debug( '%s: Installing Jetpack CRM from WP.org', $domain ); | ||
add_directory_plugin( 'zero-bs-crm' ); | ||
|
||
} | ||
|
||
}, | ||
10, | ||
3 | ||
); | ||
|
||
add_filter( | ||
'jurassic_ninja_rest_create_request_features', | ||
function ( $features, $json_params ) { | ||
|
||
if ( isset( $json_params['jpcrm'] ) ) { | ||
$features['jpcrm'] = $json_params['jpcrm']; | ||
} | ||
|
||
if ( isset( $json_params['jpcrm-version'] ) ) { | ||
$features['jpcrm-version'] = $json_params['jpcrm-version']; | ||
} | ||
|
||
if ( isset( $json_params['jpcrm-build'] ) ) { | ||
$features['jpcrm-build'] = $json_params['jpcrm-build']; | ||
} | ||
|
||
return $features; | ||
}, | ||
10, | ||
2 | ||
); | ||
} | ||
); | ||
|
||
/** | ||
* Installs and activates a specified version of Jetpack CRM from the WP.org plugin repo. | ||
* | ||
* @param string $version Version of Jetpack CRM. | ||
*/ | ||
function add_jpcrm_from_wporg( $version ) { | ||
|
||
// Verify we have a valid version number. | ||
if ( ! version_compare( $version, '1.0.0', '>=' ) ) { | ||
return new \WP_Error( 'bad_version_number', 'Bad version number.', array( 'status' => 404 ) ); | ||
} | ||
|
||
$cmd = "wp plugin install zero-bs-crm --version=$version --activate"; | ||
|
||
add_filter( | ||
'jurassic_ninja_feature_command', | ||
function ( $s ) use ( $cmd ) { | ||
return "$s && $cmd"; | ||
} | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Installs and activates a specified build of Jetpack CRM from our custom build URL. | ||
* | ||
* @param string $build Hash of build to use. | ||
*/ | ||
function add_jpcrm_from_custom_build( $build ) { | ||
|
||
// phpcs:disable Squiz.PHP.CommentedOutCode.Found | ||
|
||
/* | ||
* Require commit SHA-1 hash (40 char long hex). | ||
* if ( ! preg_match( '/^[A-Fa-f0-9]{40}$/', $build ) ) { | ||
* return new \WP_Error( 'bad_commit_hash', 'Invalid commit hash.', array( 'status' => 404 ) ); | ||
* } | ||
*/ | ||
// phpcs:enable | ||
|
||
$clean_build = str_replace( '/', '_', $build ); | ||
|
||
// note that this public link is in a public repo | ||
$jpcrm_build_base_url = 'https://jetpackcrm-builds.s3.amazonaws.com/builds/'; | ||
$jpcrm_build_url = $jpcrm_build_base_url . 'zero-bs-crm-' . $clean_build . '.zip'; | ||
|
||
$cmd = "wp plugin install $jpcrm_build_url --activate"; | ||
|
||
add_filter( | ||
'jurassic_ninja_feature_command', | ||
function ( $s ) use ( $cmd ) { | ||
return "$s && $cmd"; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* Register a shortcode which renders Jetpack Licensing controls suitable for SpecialOps usage. | ||
*/ | ||
\add_shortcode( | ||
'jn_jpcrm_options', | ||
function () { | ||
ob_start(); | ||
?> | ||
<style> | ||
.jn-jpcrm-options ul { | ||
list-style-type: none; | ||
} | ||
.jn-jpcrm-options input[type="text"] { | ||
margin-left: 25px; | ||
} | ||
</style> | ||
<div class="jn-jpcrm-options" style="display:none;"> | ||
<ul> | ||
<li><label><input type="radio" name="jpcrm-options" checked /> WP.org</label></li> | ||
<li><label><input type="radio" name="jpcrm-options" data-feature="jpcrm-version" /> Version: <input type="text" id="jpcrm-version" placeholder="4.10.1"></label></li> | ||
<li><label><input type="radio" name="jpcrm-options" data-feature="jpcrm-build" /> Build: <input type="text" id="jpcrm-build" placeholder="fix/314/rationalise_pi"></label></li> | ||
</ul> | ||
</div> | ||
<?php | ||
return ob_get_clean(); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters