Skip to content

Commit

Permalink
Classic Theme Helper: featured content usage from module to package (#…
Browse files Browse the repository at this point in the history
…37260)

* Move code from the Theme-tools Module to the Classic-Theme-Helper package

* Changelog

* Bug fixing due to namespacing

* Added deprecated annotation to the class

* Updated phan baseline for the jetpack plugin

* Using package methods instead of existing code in the modules.

* Removed wpcom code

* Phan update

* Namespacing

* Creates Loader as Singleton and calls init

* Phan update

* Revert "Removed wpcom code"

This reverts commit 3839366.

* Updated phan

* Version bump

* Version bump

* Updated phan after merge

* Use namespace in class_exists

* version bump

* Phan updates

* Updated loader from classic-theme-helper to not load yet undeprecated stuff

* Updated phan

* Fixup versions

* Changed webpack config andmoved to main class instead of loader

* Fixed main class reference in composer

* Version bump

* Still calling Featured Content from modules

* Version bump

* Added deprecated annotation to static variables
  • Loading branch information
darssen authored Jun 7, 2024
1 parent f944539 commit 30a8df6
Show file tree
Hide file tree
Showing 26 changed files with 266 additions and 513 deletions.
4 changes: 1 addition & 3 deletions projects/packages/classic-theme-helper/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return [
// # Issue statistics:
// PhanTypeMismatchArgumentInternal : 10+ occurrences
// PhanUndeclaredClassMethod : 6 occurrences
// PhanUndeclaredClassMethod : 5 occurrences
// PhanTypeInvalidDimOffset : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanNonClassMethodCall : 1 occurrence
Expand All @@ -19,12 +19,10 @@
// PhanTypeMismatchProperty : 1 occurrence
// PhanTypeMismatchPropertyProbablyReal : 1 occurrence
// PhanTypePossiblyInvalidDimOffset : 1 occurrence
// PhanUndeclaredTypeReturnType : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'_inc/lib/tonesque.php' => ['PhanNonClassMethodCall', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchPropertyProbablyReal', 'PhanUndeclaredClassMethod'],
'src/class-classic-theme-helper.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredTypeReturnType'],
'src/class-featured-content.php' => ['PhanTypeComparisonToArray', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Classic Theme Helper: Move code from module to package
4 changes: 2 additions & 2 deletions projects/packages/classic-theme-helper/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
"extra": {
"autotagger": true,
"branch-alias": {
"dev-trunk": "0.2.x-dev"
"dev-trunk": "0.3.x-dev"
},
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-classic-theme-helper/compare/v${old}...v${new}"
},
"mirror-repo": "Automattic/jetpack-classic-theme-helper",
"textdomain": "jetpack-classic-theme-helper",
"version-constants": {
"::PACKAGE_VERSION": "src/class-classic-theme-helper.php"
"::PACKAGE_VERSION": "src/class-main.php"
}
},
"suggest": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/classic-theme-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-classic-theme-helper",
"version": "0.2.1",
"version": "0.3.0-alpha",
"description": "Features used with classic themes",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/classic-theme-helper/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
/**
* Theme Tools: functions for Featured Content enhancements.
*
* @package automattic/jetpack
* @package automattic/jetpack-classic-theme-helper
*/

use Automattic\Jetpack\Assets;
namespace Automattic\Jetpack\Classic_Theme_Helper;

if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {
use Automattic\Jetpack\Assets;
use WP_Customize_Manager;
use WP_Query;
if ( ! class_exists( __NAMESPACE__ . '\Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) {

/**
* Featured Content.
Expand Down Expand Up @@ -767,7 +770,7 @@ function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) {
$copy_dirs[] = __FILE__;
return $copy_dirs;
}
add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' );
add_action( 'restapi_theme_action_copy_dirs', __NAMESPACE__ . '\wpcom_rest_api_featured_content_copy_plugin_actions' );

/**
* Delayed initialization for API Requests.
Expand All @@ -780,7 +783,7 @@ function wpcom_rest_request_before_callbacks( $request ) {
}

if ( defined( 'IS_WPCOM' ) && IS_WPCOM && defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) {
add_filter( 'rest_request_before_callbacks', 'wpcom_rest_request_before_callbacks' );
add_filter( 'rest_request_before_callbacks', __NAMESPACE__ . '\wpcom_rest_request_before_callbacks' );
}

Featured_Content::setup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
* @package automattic/jetpack-classic-theme-helper
*/

namespace Automattic\Jetpack;
namespace Automattic\Jetpack\Classic_Theme_Helper;

use WP_Error;

/**
* Classic Theme Helper.
* Classic Theme Helper Loader.
*/
class Classic_Theme_Helper {
class Main {

const PACKAGE_VERSION = '0.2.1';
const PACKAGE_VERSION = '0.3.0-alpha';

/**
* Modules to include.
Expand All @@ -21,16 +23,28 @@ class Classic_Theme_Helper {
*/
public $modules = array(
'class-featured-content.php',
'responsive-videos.php',
// 'responsive-videos.php',
);

/** Holds the singleton instance of the Loader
*
* @var Main
*/
public static $instance = null;

/**
* Initialize Classic Theme Helper.
* Initialize the Loader.
*/
public function init() {
add_action( 'plugins_loaded', array( $this, 'load_modules' ) );
add_action( 'init', array( __CLASS__, 'jetpack_load_theme_tools' ), 30 );
add_action( 'after_setup_theme', array( __CLASS__, 'jetpack_load_theme_compat' ), -1 );
public static function init() {
if ( ! self::$instance ) {
self::$instance = new Main();
add_action( 'plugins_loaded', array( self::$instance, 'load_modules' ) );
// TODO Commenting below since we still load them from theme-tools module
// add_action( 'init', array( __CLASS__, 'jetpack_load_theme_tools' ), 30 );
// add_action( 'after_setup_theme', array( __CLASS__, 'jetpack_load_theme_compat' ), -1 );
}

return self::$instance;
}

/**
Expand All @@ -43,7 +57,7 @@ public function load_modules() {
// @param array $modules Array of modules to include.
$modules = apply_filters( 'jetpack_classic_theme_helper_modules', $this->modules );
foreach ( $modules as $module ) {
require_once __DIR__ . $module;
require_once __DIR__ . '/' . $module;
}
}

Expand Down Expand Up @@ -110,3 +124,4 @@ private static function jetpack_require_compat_file( $key, $files ) {
}
}
}
Main::init();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


6 changes: 3 additions & 3 deletions projects/plugins/classic-theme-helper-plugin/composer.lock

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

17 changes: 10 additions & 7 deletions projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// PhanPluginDuplicateConditionalNullCoalescing : 280+ occurrences
// PhanNoopNew : 200+ occurrences
// PhanTypeMismatchReturn : 150+ occurrences
// PhanTypeMismatchReturnProbablyReal : 150+ occurrences
// PhanTypeMismatchReturnProbablyReal : 140+ occurrences
// PhanDeprecatedFunction : 120+ occurrences
// PhanTypePossiblyInvalidDimOffset : 95+ occurrences
// PhanRedundantCondition : 70+ occurrences
Expand All @@ -39,24 +39,25 @@
// PhanUndeclaredFunction : 20+ occurrences
// PhanPluginDuplicateExpressionAssignmentOperation : 15+ occurrences
// PhanPluginMixedKeyNoKey : 15+ occurrences
// PhanRedefineFunction : 15+ occurrences
// PhanSuspiciousMagicConstant : 15+ occurrences
// PhanTypeExpectedObjectPropAccessButGotNull : 15+ occurrences
// PhanTypeMismatchArgumentNullableInternal : 15+ occurrences
// PhanTypeMismatchPropertyDefault : 15+ occurrences
// PhanUndeclaredMethod : 15+ occurrences
// PhanRedefineClass : 10+ occurrences
// PhanRedundantConditionInLoop : 10+ occurrences
// PhanTypeComparisonToArray : 10+ occurrences
// PhanTypeInvalidLeftOperandOfNumericOp : 10+ occurrences
// PhanTypeMismatchProperty : 10+ occurrences
// PhanTypeMismatchReturnNullable : 10+ occurrences
// PhanTypeComparisonToArray : 9 occurrences
// PhanPluginRedundantAssignment : 8 occurrences
// PhanDeprecatedClass : 7 occurrences
// PhanTypeMismatchArgumentInternalReal : 7 occurrences
// PhanCommentAbstractOnInheritedMethod : 6 occurrences
// PhanRedefineFunction : 6 occurrences
// PhanImpossibleCondition : 5 occurrences
// PhanNonClassMethodCall : 5 occurrences
// PhanRedefinedClassReference : 5 occurrences
// PhanTypeArraySuspiciousNull : 5 occurrences
// PhanTypeMismatchDimAssignment : 5 occurrences
// PhanTypeSuspiciousStringExpression : 5 occurrences
Expand Down Expand Up @@ -95,7 +96,6 @@
// PhanPluginRedundantAssignmentInLoop : 1 occurrence
// PhanTypeComparisonFromArray : 1 occurrence
// PhanTypeInstantiateAbstract : 1 occurrence
// PhanTypeInvalidCallableArraySize : 1 occurrence
// PhanTypeSuspiciousEcho : 1 occurrence
// PhanTypeVoidArgument : 1 occurrence
// PhanUndeclaredExtendedClass : 1 occurrence
Expand Down Expand Up @@ -165,7 +165,7 @@
'_inc/lib/icalendar-reader.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPluginDuplicateExpressionAssignmentOperation', 'PhanPossiblyUndeclaredVariable', 'PhanRedundantCondition', 'PhanTypeInvalidLeftOperandOfNumericOp', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypePossiblyInvalidDimOffset', 'PhanUndeclaredProperty'],
'_inc/lib/markdown/extra.php' => ['PhanImpossibleConditionInLoop', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturn', 'PhanUndeclaredProperty'],
'_inc/lib/plans.php' => ['PhanTypeMismatchReturn', 'PhanTypeMismatchReturnProbablyReal'],
'_inc/lib/tonesque.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'],
'_inc/lib/tonesque.php' => ['PhanRedefineClass', 'PhanRedefinedClassReference', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'],
'_inc/lib/widgets.php' => ['PhanRedundantConditionInLoop', 'PhanTypeArraySuspiciousNullable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchReturn'],
'_inc/social-logos.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'class-jetpack-gallery-settings.php' => ['PhanNoopNew'],
Expand Down Expand Up @@ -441,16 +441,19 @@
'modules/subscriptions.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchDefault', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach'],
'modules/subscriptions/subscribe-modal/class-jetpack-subscribe-modal.php' => ['PhanTypeMismatchReturnNullable'],
'modules/subscriptions/views.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMissingReturn', 'PhanTypePossiblyInvalidDimOffset'],
'modules/theme-tools/compat/twentysixteen.php' => ['PhanParamTooMany'],
'modules/theme-tools/compat/twentyfifteen.php' => ['PhanRedefineFunction'],
'modules/theme-tools/compat/twentyfourteen.php' => ['PhanRedefineFunction'],
'modules/theme-tools/compat/twentynineteen.php' => ['PhanRedefineFunction'],
'modules/theme-tools/compat/twentysixteen.php' => ['PhanParamTooMany', 'PhanRedefineFunction'],
'modules/theme-tools/compat/twentytwenty.php' => ['PhanParamTooMany'],
'modules/theme-tools/content-options/author-bio.php' => ['PhanTypeMismatchArgument'],
'modules/theme-tools/content-options/blog-display.php' => ['PhanPluginDuplicateExpressionAssignmentOperation'],
'modules/theme-tools/content-options/customizer.php' => ['PhanTypeMismatchReturn'],
'modules/theme-tools/content-options/featured-images-fallback.php' => ['PhanTypeMismatchArgument', 'PhanTypePossiblyInvalidDimOffset'],
'modules/theme-tools/content-options/featured-images.php' => ['PhanPluginSimplifyExpressionBool', 'PhanTypeMismatchArgument'],
'modules/theme-tools/content-options/post-details.php' => ['PhanTypeArraySuspiciousNullable'],
'modules/theme-tools/featured-content.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeComparisonToArray', 'PhanTypeInvalidCallableArraySize', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanTypeMismatchReturnProbablyReal', 'PhanTypeMissingReturn', 'PhanTypePossiblyInvalidDimOffset'],
'modules/theme-tools/random-redirect.php' => ['PhanTypeMismatchArgument'],
'modules/theme-tools/responsive-videos.php' => ['PhanRedefineFunction'],
'modules/theme-tools/site-breadcrumbs.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchReturn'],
'modules/theme-tools/site-logo/inc/class-site-logo.php' => ['PhanRedundantCondition', 'PhanTypeComparisonToArray', 'PhanTypeMismatchReturn'],
'modules/theme-tools/site-logo/inc/functions.php' => ['PhanTypeMismatchReturnProbablyReal'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Classic Theme Helper: Move code from module to package
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated composer.lock.


1 change: 1 addition & 0 deletions projects/plugins/jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"automattic/jetpack-blocks": "@dev",
"automattic/jetpack-boost-speed-score": "@dev",
"automattic/jetpack-calypsoify": "@dev",
"automattic/jetpack-classic-theme-helper": "@dev",
"automattic/jetpack-compat": "@dev",
"automattic/jetpack-composer-plugin": "@dev",
"automattic/jetpack-config": "@dev",
Expand Down
Loading

0 comments on commit 30a8df6

Please sign in to comment.