Skip to content

Commit

Permalink
CRM: Use version constant for monorepo tooling compatibility (#41408)
Browse files Browse the repository at this point in the history
* Add version constant to class

* Flag version constant for auto-update

* Defer to version constant

* Use version constant everywhere

* Remove unneeded file

* Add changelog

* Update composer.lock file

* Suppress Phan error
  • Loading branch information
tbradsha authored Jan 31, 2025
1 parent 3ab4b71 commit 4a02ca9
Show file tree
Hide file tree
Showing 27 changed files with 221 additions and 375 deletions.
9 changes: 4 additions & 5 deletions projects/plugins/crm/admin/activation/before-you-go.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@

// js
wp_enqueue_script( 'jquery' );
// not really needed. wp_enqueue_script('zbsbeforeyougojs', plugins_url('/js/before-you-go/jquery.blockUI.min.js',ZBS_ROOTFILE), array( 'jquery' ), $zbs->version);

// css
wp_enqueue_style( 'zbsbeforeyougocssloadstyles', plugins_url( '/css/before-you-go/loadstyles.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbsbeforeyougocssopensans', plugins_url( '/css/before-you-go/opensans' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbsbeforeyougocssadminmin', plugins_url( '/css/before-you-go/admin.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbsbeforeyougocssexitform', plugins_url( '/css/before-you-go/zbs-exitform.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbsbeforeyougocssloadstyles', plugins_url( '/css/before-you-go/loadstyles.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbsbeforeyougocssopensans', plugins_url( '/css/before-you-go/opensans' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbsbeforeyougocssadminmin', plugins_url( '/css/before-you-go/admin.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbsbeforeyougocssexitform', plugins_url( '/css/before-you-go/zbs-exitform.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
$style_handles = array( 'zbsbeforeyougocssloadstyles', 'zbsbeforeyougocssopensans', 'zbsbeforeyougocssadminmin', 'zbsbeforeyougocssexitform' );

?><!DOCTYPE html>
Expand Down
22 changes: 12 additions & 10 deletions projects/plugins/crm/admin/activation/welcome-to-jpcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@
// } Assets we need specifically here

// js
// phpcs:disable WordPress.WP.EnqueuedResourceParameters.NotInFooter
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'zbswelcomeblock', plugins_url( '/js/welcome-to-zbs/jquery.blockUI.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs->version );
wp_enqueue_script( 'zbswelcomebootstrap', plugins_url( '/js/welcome-to-zbs/bootstrap.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs->version );
wp_enqueue_script( 'zbswelcomewizard', plugins_url( '/js/welcome-to-zbs/wizard2' . wp_scripts_get_suffix() . '.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs->version );
wp_enqueue_script( 'zbswelcomeblock', plugins_url( '/js/welcome-to-zbs/jquery.blockUI.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs::VERSION );
wp_enqueue_script( 'zbswelcomebootstrap', plugins_url( '/js/welcome-to-zbs/bootstrap.min.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs::VERSION );
wp_enqueue_script( 'zbswelcomewizard', plugins_url( '/js/welcome-to-zbs/wizard2' . wp_scripts_get_suffix() . '.js', ZBS_ROOTFILE ), array( 'jquery' ), $zbs::VERSION );

// css
wp_enqueue_style( 'zbswelcomebootstrap', plugins_url( '/css/welcome-to-zbs/bootstrap.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomeloadstyles', plugins_url( '/css/welcome-to-zbs/loadstyles' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomeopensans', plugins_url( '/css/welcome-to-zbs/opensans' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomeadmin', plugins_url( '/css/welcome-to-zbs/admin.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomeexitform', plugins_url( '/css/welcome-to-zbs/zbs-exitform' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomeactivation', plugins_url( '/css/welcome-to-zbs/activation.min.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomewizard', plugins_url( '/css/welcome-to-zbs/wizard' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs->version );
wp_enqueue_style( 'zbswelcomebootstrap', plugins_url( '/css/welcome-to-zbs/bootstrap.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomeloadstyles', plugins_url( '/css/welcome-to-zbs/loadstyles' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomeopensans', plugins_url( '/css/welcome-to-zbs/opensans' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomeadmin', plugins_url( '/css/welcome-to-zbs/admin.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomeexitform', plugins_url( '/css/welcome-to-zbs/zbs-exitform' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomeactivation', plugins_url( '/css/welcome-to-zbs/activation.min.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
wp_enqueue_style( 'zbswelcomewizard', plugins_url( '/css/welcome-to-zbs/wizard' . wp_scripts_get_suffix() . '.css', ZBS_ROOTFILE ), array(), $zbs::VERSION );
$style_handles = array( 'zbswelcomebootstrap', 'zbswelcomeloadstyles', 'zbswelcomeopensans', 'zbswelcomeadmin', 'zbswelcomeexitform', 'zbswelcomeactivation', 'zbswelcomewizard' );
// phpcs:enable WordPress.WP.EnqueuedResourceParameters.NotInFooter

// } Image URLS
$assetsURLI = ZEROBSCRM_URL . 'i/';
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/crm/admin/activation/wizard.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function zbs_wizard_fin() {
'ef' => $crm_enable_forms,
'ew' => $crm_enable_woo_module,
'ems' => $crm_menu_style,
'v' => $zbs->version,
'v' => $zbs::VERSION,
'cu' => $crm_curr,
);
update_option( 'zbs_initopts_' . time(), $init_options, false );
Expand Down
6 changes: 5 additions & 1 deletion projects/plugins/crm/admin/settings/mail-delivery.page.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,5 +556,9 @@

</style>

<?php wp_enqueue_script( 'jpcrm-admin-maildelivery', plugins_url( '/js/jpcrm-admin-maildelivery' . wp_scripts_get_suffix() . '.js', ZBS_ROOTFILE ), array(), $zbs->version ); ?>
<?php
// phpcs:disable WordPress.WP.EnqueuedResourceParameters.NotInFooter
wp_enqueue_script( 'jpcrm-admin-maildelivery', plugins_url( '/js/jpcrm-admin-maildelivery' . wp_scripts_get_suffix() . '.js', ZBS_ROOTFILE ), array(), $zbs::VERSION );
// phpcs:enable WordPress.WP.EnqueuedResourceParameters.NotInFooter
?>
</div>
2 changes: 1 addition & 1 deletion projects/plugins/crm/api/status.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$reply = array(
'status' => __( 'Successful Connection', 'zero-bs-crm' ),
'message' => __( 'Your API Connection with Jetpack CRM is functioning correctly.', 'zero-bs-crm' ),
'crm_version' => $zbs->version,
'crm_version' => $zbs::VERSION,
'db_version' => $zbs->db_version,
);

Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/crm/changelog/fix-crm-add_version_constant
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Code: Introduce version constant in main plugin class.
3 changes: 3 additions & 0 deletions projects/plugins/crm/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
"link-template": "https://github.com/Automattic/jetpack-crm/compare/${old}...${new}"
},
"release-branch-prefix": "crm",
"version-constants": {
"::VERSION": "includes/ZeroBSCRM.Core.php"
},
"wp-plugin-slug": "zero-bs-crm",
"wp-svn-autopublish": true
}
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/crm/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/plugins/crm/includes/ZeroBSCRM.AdminStyling.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function jpcrm_footer_credit_version( $content ) {
global $zbs;
$showpoweredby_admin = $zbs->settings->get( 'showpoweredby_admin' ) === 1 ? true : false;
if ( $showpoweredby_admin ) {
return sprintf( 'Jetpack CRM v%s', $zbs->version );
return sprintf( 'Jetpack CRM v%s', $zbs::VERSION );
}
##/WLREMOVE

Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/crm/includes/ZeroBSCRM.CSVImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function zeroBSCRM_CSVImporterLiteadmin_menu() {

global $zbs,$zeroBSCRM_CSVImporterLiteslugs; // req

wp_register_style( 'zerobscrm-csvimporter-admcss', ZEROBSCRM_URL . 'css/ZeroBSCRM.admin.csvimporter' . wp_scripts_get_suffix() . '.css', array(), $zbs->version );
wp_register_style( 'zerobscrm-csvimporter-admcss', ZEROBSCRM_URL . 'css/ZeroBSCRM.admin.csvimporter' . wp_scripts_get_suffix() . '.css', array(), $zbs::VERSION );
$csv_admin_page = add_submenu_page( 'jpcrm-hidden', 'CSV Importer', 'CSV Importer', 'admin_zerobs_customers', $zbs->slugs['csvlite'], 'zeroBSCRM_CSVImporterLitepages_app', 1 ); // phpcs:ignore WordPress.WP.Capabilities.Unknown
add_action( "admin_print_styles-{$csv_admin_page}", 'zeroBSCRM_CSVImporter_lite_admin_styles' );
add_action( "admin_print_styles-{$csv_admin_page}", 'zeroBSCRM_global_admin_styles' ); // } and this.
Expand Down
29 changes: 18 additions & 11 deletions projects/plugins/crm/includes/ZeroBSCRM.Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
final class ZeroBSCRM {

/**
* ZeroBSCRM version.
* Jetpack CRM version.
*
* @var string
*/
public $version = '6.5.1';
const VERSION = '6.5.1';

/**
* Jetpack CRM version (used in various extensions as of January 2025).
*
* @deprecated
* @var string
*/
public $version = '';

/**
* WordPress version tested with.
Expand Down Expand Up @@ -545,6 +553,8 @@ public function __get( $key ) {
* Jetpack CRM Constructor.
*/
public function __construct() {
// @phan-suppress-next-line PhanDeprecatedProperty - Define old property for backward compatibility.
$this->version = $this::VERSION;

// Simple global definitions without loading any core files...
// required for verify_minimum_requirements()
Expand Down Expand Up @@ -619,10 +629,10 @@ private function verify_minimum_requirements() {
$this->setupUrlsSlugsEtc();

// build message
$message_html = '<p>' . sprintf( esc_html__( 'This version of CRM (%1$s) requires an upgraded database (3.0). Your database is using an older version than this (%2$s). To use CRM you will need to install version 4 of CRM and run the database upgrade.', 'zero-bs-crm' ), $this->version, $this->dal_version ) . '</p>'; // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$message_html = '<p>' . sprintf( esc_html__( 'This version of CRM (%1$s) requires an upgraded database (3.0). Your database is using an older version than this (%2$s). To use CRM you will need to install version 4 of CRM and run the database upgrade.', 'zero-bs-crm' ), $this::VERSION, $this->dal_version ) . '</p>'; // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment

##WLREMOVE
$message_html = '<p>' . sprintf( esc_html__( 'This version of Jetpack CRM (%1$s) requires an upgraded database (3.0). Your database is using an older version than this (%2$s). To use Jetpack CRM you will need to install version 4 of Jetpack CRM and run the database upgrade.', 'zero-bs-crm' ), $this->version, $this->dal_version ) . '</p>'; // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$message_html = '<p>' . sprintf( esc_html__( 'This version of Jetpack CRM (%1$s) requires an upgraded database (3.0). Your database is using an older version than this (%2$s). To use Jetpack CRM you will need to install version 4 of Jetpack CRM and run the database upgrade.', 'zero-bs-crm' ), $this::VERSION, $this->dal_version ) . '</p>'; // phpcs:ignore WordPress.WP.I18n.MissingTranslatorsComment
$message_html .= '<p><a href="' . esc_url( $this->urls['kb-pre-v5-migration-todo'] ) . '" target="_blank" class="button">' . __( 'Read the guide on migrating', 'zero-bs-crm' ) . '</a></p>';
##/WLREMOVE

Expand All @@ -639,7 +649,7 @@ private function verify_minimum_requirements() {
} elseif ( ! function_exists( 'openssl_get_cipher_methods' ) ) {

// build message
$message_html = '<p>' . sprintf( __( 'Jetpack CRM uses the OpenSSL extension for PHP to properly protect sensitive data. Most PHP environments have this installed by default, but it seems yours does not; we recommend contacting your host for further help.', 'zero-bs-crm' ), $this->version, $this->dal_version ) . '</p>';
$message_html = '<p>' . sprintf( __( 'Jetpack CRM uses the OpenSSL extension for PHP to properly protect sensitive data. Most PHP environments have this installed by default, but it seems yours does not; we recommend contacting your host for further help.', 'zero-bs-crm' ), $this::VERSION, $this->dal_version ) . '</p>';
$message_html .= '<p><a href="' . esc_url( 'https://www.php.net/manual/en/book.openssl.php' ) . '" target="_blank" class="button">' . __( 'PHP docs on OpenSSL', 'zero-bs-crm' ) . '</a></p>';

$this->add_wp_admin_notice(
Expand Down Expand Up @@ -1326,9 +1336,6 @@ public function includes() {
// } Put Plugin update message (notifications into the transient /wp-admin/plugins.php) page.. that way the nag message is not needed at the top of pages (and will always show, not need to be dismissed)
require_once ZEROBSCRM_INCLUDE_PATH . 'ZeroBSCRM.PluginUpdates.php';

// v3.0 update coming, warning
require_once ZEROBSCRM_INCLUDE_PATH . 'ZeroBSCRM.PluginUpdates.ImminentRelease.php';

// } FROM PLUGIN HUNT THEME - LOT OF USEFUL CODE IN HERE.
require_once ZEROBSCRM_INCLUDE_PATH . 'ZeroBSCRM.NotifyMe.php';

Expand Down Expand Up @@ -1596,7 +1603,7 @@ public function preInit() {

// } Setup Config (centralises version numbers temp)
global $zeroBSCRM_Conf_Setup;
$zeroBSCRM_Conf_Setup['conf_pluginver'] = $this->version;
$zeroBSCRM_Conf_Setup['conf_pluginver'] = $this::VERSION; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
$zeroBSCRM_Conf_Setup['conf_plugindbver'] = $this->db_version;

// Not needed yet :) do_action( 'before_zerobscrm_settings_init' );
Expand Down Expand Up @@ -2192,8 +2199,8 @@ public function include_updater() {
$this->update_api_version,
ZBS_ROOTFILE,
array(
'version' => $this->version,
'license' => false, // license initiated to false..
'version' => $this::VERSION,
'license' => false, // license initiated to false..
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public function html( $form, $metabox ) {
$zbsfs = 'simple'; if (is_array($form) && isset($form['style'])) $zbsfs = $form['style'];

// get js url
$formjs = ZEROBSCRM_URL . 'js/ZeroBSCRM.leadform.js?ver='.$zbs->version;
$formjs = ZEROBSCRM_URL . 'js/ZeroBSCRM.leadform.js?ver=' . $zbs::VERSION;

?><div id="form-embed">
<h1 class="welcomeh1"><?php esc_html_e('Embed Code',"zero-bs-crm");?></h1>
Expand Down
61 changes: 30 additions & 31 deletions projects/plugins/crm/includes/ZeroBSCRM.NotifyMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,39 @@ function zeroBSCRM_notifyme_createDBtable(){


function zeroBSCRM_notifyme_scripts(){

global $zbs;
wp_enqueue_script("jquery");
wp_enqueue_script('notifyme-front', ZEROBSCRM_URL . 'js/lib/notifyme-front.min.js',array('jquery'), $zbs->version );
wp_enqueue_style('notifyme-css', ZEROBSCRM_URL . 'css/lib/notifyme-front.min.css', array(), $zbs->version );

#} this does the browser notifications
wp_register_script( 'notifyme_push', ZEROBSCRM_URL . 'js/lib/push.min.js', array( 'jquery' ) , $zbs->version, true );
wp_enqueue_script( 'notifyme_push' );

#} this stores things in cookies, so not to keep notifying
wp_register_script( 'notifyme_cookie', ZEROBSCRM_URL . 'js/lib/cookie.min.js', array( 'jquery' ) , $zbs->version, true );
wp_enqueue_script( 'notifyme_cookie' );

#} this is the browser notification icon.
$notify_logo = jpcrm_get_logo();

#} this is which user to notify for..
$cid = get_current_user_id();

#} we want to browser notify our users :-)
$notification_meta['browser_push'] = 1;
$args = array(
'ph_notify_logo' => $notify_logo,
'current_user' => $cid,
'notification_nonce' => wp_create_nonce( "notifyme_nonce" ),
'notification_settings' => $notification_meta,
'ajaxurl' => admin_url( 'admin-ajax.php' )
);
wp_localize_script('notifyme_push','notifyme',$args);
global $zbs;
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'notifyme-front', ZEROBSCRM_URL . 'js/lib/notifyme-front.min.js', array( 'jquery' ), $zbs::VERSION ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter
wp_enqueue_style( 'notifyme-css', ZEROBSCRM_URL . 'css/lib/notifyme-front.min.css', array(), $zbs::VERSION );

#} this does the browser notifications
wp_register_script( 'notifyme_push', ZEROBSCRM_URL . 'js/lib/push.min.js', array( 'jquery' ), $zbs::VERSION, true );
wp_enqueue_script( 'notifyme_push' );

#} this stores things in cookies, so not to keep notifying
wp_register_script( 'notifyme_cookie', ZEROBSCRM_URL . 'js/lib/cookie.min.js', array( 'jquery' ), $zbs::VERSION, true );
wp_enqueue_script( 'notifyme_cookie' );

#} this is the browser notification icon.
$notify_logo = jpcrm_get_logo();

#} this is which user to notify for..
$cid = get_current_user_id();

#} we want to browser notify our users :-)
$notification_meta = array( 'browser_push' => 1 );

$args = array(
'ph_notify_logo' => $notify_logo,
'current_user' => $cid,
'notification_nonce' => wp_create_nonce( 'notifyme_nonce' ),
'notification_settings' => $notification_meta,
'ajaxurl' => admin_url( 'admin-ajax.php' ),
);
wp_localize_script( 'notifyme_push', 'notifyme', $args );
}
add_action( 'zbs-global-admin-styles', 'zeroBSCRM_notifyme_scripts' );


//ADD ANY CORE FUNCTIONS FOR THE PLUGIN HERE
function zeroBSCRM_notify_me(){
global $zbs;
Expand Down
6 changes: 3 additions & 3 deletions projects/plugins/crm/includes/ZeroBSCRM.OnboardMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function zeroBS_onboardme_scripts(){

// Changed from bootstrap tour to hopscotch
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'onboardme-front', ZEROBSCRM_URL . 'js/lib/hopscotch.min.js', array( 'jquery' ), $zbs->version, true );
wp_enqueue_style( 'onboardme-css', ZEROBSCRM_URL . 'css/lib/hopscotch.min.css', array(), $zbs->version );
wp_enqueue_script( 'tour-front', ZEROBSCRM_URL . 'js/ZeroBSCRM.admin.tour' . wp_scripts_get_suffix() . '.js', array( 'jquery', 'onboardme-front' ), $zbs->version, true );
wp_enqueue_script( 'onboardme-front', ZEROBSCRM_URL . 'js/lib/hopscotch.min.js', array( 'jquery' ), $zbs::VERSION, true );
wp_enqueue_style( 'onboardme-css', ZEROBSCRM_URL . 'css/lib/hopscotch.min.css', array(), $zbs::VERSION );
wp_enqueue_script( 'tour-front', ZEROBSCRM_URL . 'js/ZeroBSCRM.admin.tour' . wp_scripts_get_suffix() . '.js', array( 'jquery', 'onboardme-front' ), $zbs::VERSION, true );

$zbs_tour_root = admin_url();

Expand Down
Loading

0 comments on commit 4a02ca9

Please sign in to comment.