Skip to content

Commit 6531537

Browse files
committed
PHPCompatibility check
1 parent 1c4b3b0 commit 6531537

6 files changed

Lines changed: 44 additions & 43 deletions

File tree

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"php-stubs/wordpress-stubs": "^6",
3131
"wp-coding-standards/wpcs": "^3",
3232
"dealerdirect/phpcodesniffer-composer-installer": "^1",
33-
"phpcompatibility/phpcompatibility-wp": "^2",
33+
"phpcompatibility/phpcompatibility-wp": "*",
34+
"phpcompatibility/php-compatibility": "dev-develop as 9.99.99",
3435
"yoast/phpunit-polyfills": "^3",
3536
"phpunit/phpunit": "^9 || ^10 || ^11 || ^12"
3637
},
@@ -40,11 +41,13 @@
4041
"dealerdirect/phpcodesniffer-composer-installer": true
4142
}
4243
},
44+
"minimum-stability": "dev",
45+
"prefer-stable": true,
4346
"scripts": {
4447
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2048M",
4548
"phpstan-baseline": "vendor/bin/phpstan analyse --memory-limit=2048M --generate-baseline",
4649
"phpcs": "vendor/bin/phpcs -p -v -s --standard=phpcs.xml.dist $(find . -name '*.php')",
4750
"phpcbf": "vendor/bin/phpcbf -p -v -s --standard=phpcs.xml.dist $(find . -name '*.php')",
48-
"zip": "mkdir -p build && zip -X -r build/contextual-related-posts.zip . -x '*.git*' 'node_modules/*' '.*' '*/.git*' '*/.DS_Store' 'CODE_OF_CONDUCT.md' 'CONTRIBUTING.md' 'ISSUE_TEMPLATE.md' 'PULL_REQUEST_TEMPLATE.md' '*.dist' '*.yml' '*.neon' 'composer.*' 'package.json' 'dev-helpers**' 'build**' 'wporg-assets**' 'phpunit**'"
51+
"zip": "mkdir -p build && zip -X -r build/$(basename $(pwd)).zip . -x '*.git*' 'node_modules/*' '.*' '*/.git*' '*/.DS_Store' 'CODE_OF_CONDUCT.md' 'CONTRIBUTING.md' 'ISSUE_TEMPLATE.md' 'PULL_REQUEST_TEMPLATE.md' '*.dist' '*.yml' '*.neon' 'composer.*' 'package.json' 'dev-helpers**' 'build**' 'wporg-assets**'"
4952
}
50-
}
53+
}

includes/admin/class-settings.php

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
class Settings {
2626

27-
2827
/**
2928
* Settings API instance.
3029
*
@@ -697,7 +696,7 @@ public static function settings_list() {
697696
'id' => 'cornerstone_post_ids',
698697
'name' => esc_html__( 'Cornerstone IDs', 'contextual-related-posts' ),
699698
'desc' => sprintf(
700-
/* translators: 1: Opening anchor tag, 2: Closing anchor tag */
699+
/* translators: 1: Opening anchor tag, 2: Closing anchor tag */
701700
esc_html__( 'Comma-separated list of post/page or custom post type IDs to be used as cornerstone posts. Posts with these IDs will be randomly selected and then included in the list of related posts. Roughly 20%% of the related posts will be chosen from this list. Learn more about %1$sCornerstone Posts%2$s.', 'contextual-related-posts' ),
702701
'<a href="https://webberzone.com/support/knowledgebase/cornerstone-posts-in-contextual-related-posts/" target="_blank">',
703702
'</a>'
@@ -1078,7 +1077,7 @@ public static function settings_feed() {
10781077
*/
10791078
public static function settings_performance() {
10801079
$custom_tables_desc = sprintf(
1081-
/* translators: 1: Opening a tag, 2: Closing a tag */
1080+
/* translators: 1: Opening a tag, 2: Closing a tag */
10821081
esc_html__( 'Efficient Content Storage and Indexing (ECSI) creates a dedicated database table optimized for related content queries. This enhances performance, particularly on sites with a large number of posts or high traffic. To create the ECSI tables, visit the %1$sTools tab%2$s.', 'contextual-related-posts' ),
10831082
'<a href="' . esc_url( admin_url( 'tools.php?page=crp_tools_page' ) ) . '" target="_blank">',
10841083
'</a>'
@@ -1174,7 +1173,7 @@ public static function settings_performance() {
11741173
/**
11751174
* Get the various styles.
11761175
*
1177-
* @since 3.5.0
1176+
* @since 3.5.0
11781177
* @return array Associative array of styles.
11791178
*/
11801179
public static function get_styles() {
@@ -1225,7 +1224,7 @@ public static function get_styles() {
12251224
/**
12261225
* Get the various order settings.
12271226
*
1228-
* @since 3.5.0
1227+
* @since 3.5.0
12291228
* @return array Order settings.
12301229
*/
12311230
public static function get_orderings() {
@@ -1251,7 +1250,7 @@ public static function get_orderings() {
12511250
*
12521251
* @since 3.5.0
12531252
*
1254-
* @param array $links Array of links.
1253+
* @param array $links Array of links.
12551254
* @return array
12561255
*/
12571256
public function plugin_actions_links( $links ) {
@@ -1269,8 +1268,8 @@ public function plugin_actions_links( $links ) {
12691268
*
12701269
* @since 3.5.0
12711270
*
1272-
* @param array $links Array of Links.
1273-
* @param string $file Current file.
1271+
* @param array $links Array of Links.
1272+
* @param string $file Current file.
12741273
* @return array
12751274
*/
12761275
public function plugin_row_meta( $links, $file ) {
@@ -1294,14 +1293,14 @@ public function plugin_row_meta( $links, $file ) {
12941293
*/
12951294
public function get_help_sidebar() {
12961295
$help_sidebar =
1297-
/* translators: 1: Plugin support site link. */
1298-
'<p>' . sprintf( __( 'For more information or how to get support visit the <a href="%s" target="_blank">support site</a>.', 'contextual-related-posts' ), esc_url( 'https://webberzone.com/support/' ) ) . '</p>' .
1299-
'<p>' . sprintf(
1300-
/* translators: 1: Github issues link, 2: Github plugin page link. */
1301-
__( '<a href="%1$s" target="_blank">Post an issue</a> on <a href="%2$s" target="_blank">GitHub</a> (bug reports only).', 'contextual-related-posts' ),
1302-
esc_url( 'https://github.com/WebberZone/contextual-related-posts/issues' ),
1303-
esc_url( 'https://github.com/WebberZone/contextual-related-posts' )
1304-
) . '</p>';
1296+
/* translators: 1: Plugin support site link. */
1297+
'<p>' . sprintf( __( 'For more information or how to get support visit the <a href="%s" target="_blank">support site</a>.', 'contextual-related-posts' ), esc_url( 'https://webberzone.com/support/' ) ) . '</p>' .
1298+
'<p>' . sprintf(
1299+
/* translators: 1: Github issues link, 2: Github plugin page link. */
1300+
__( '<a href="%1$s" target="_blank">Post an issue</a> on <a href="%2$s" target="_blank">GitHub</a> (bug reports only).', 'contextual-related-posts' ),
1301+
esc_url( 'https://github.com/WebberZone/contextual-related-posts/issues' ),
1302+
esc_url( 'https://github.com/WebberZone/contextual-related-posts' )
1303+
) . '</p>';
13051304

13061305
/**
13071306
* Filter to modify the help sidebar content.
@@ -1336,12 +1335,12 @@ public function get_help_tabs() {
13361335
'title' => __( 'Tools', 'contextual-related-posts' ),
13371336
'content' =>
13381337
'<p>' . __( 'This screen provides some tools that help maintain certain features of Contextual Related Posts.', 'contextual-related-posts' ) . '</p>' .
1339-
'<p>' . __( 'Clear the cache, recreate the fulltext indices (including code to manually run this in phpMyAdmin), export/import settings and delete the older settings.', 'contextual-related-posts' ) . '</p>' .
1340-
'<p>' . sprintf(
1341-
/* translators: 1: Link to Knowledge Base article. */
1342-
__( 'You can find more information on each of these tools in this <a href="%1$s" target="_blank">knowledgebase article</a>.', 'contextual-related-posts' ),
1343-
esc_url( 'https://webberzone.com/support/knowledgebase/contextual-related-posts-settings-tools/' )
1344-
) . '</p>',
1338+
'<p>' . __( 'Clear the cache, recreate the fulltext indices (including code to manually run this in phpMyAdmin), export/import settings and delete the older settings.', 'contextual-related-posts' ) . '</p>' .
1339+
'<p>' . sprintf(
1340+
/* translators: 1: Link to Knowledge Base article. */
1341+
__( 'You can find more information on each of these tools in this <a href="%1$s" target="_blank">knowledgebase article</a>.', 'contextual-related-posts' ),
1342+
esc_url( 'https://webberzone.com/support/knowledgebase/contextual-related-posts-settings-tools/' )
1343+
) . '</p>',
13451344
),
13461345
);
13471346

@@ -1362,7 +1361,7 @@ public function get_help_tabs() {
13621361
*/
13631362
public static function get_admin_footer_text() {
13641363
return sprintf(
1365-
/* translators: 1: Opening achor tag with Plugin page link, 2: Closing anchor tag, 3: Opening anchor tag with review link. */
1364+
/* translators: 1: Opening achor tag with Plugin page link, 2: Closing anchor tag, 3: Opening anchor tag with review link. */
13661365
__( 'Thank you for using %1$sContextual Related Posts by WebberZone%2$s! Please %3$srate us%2$s on %3$sWordPress.org%2$s', 'contextual-related-posts' ),
13671366
'<a href="https://webberzone.com/plugins/contextual-related-posts/" target="_blank">',
13681367
'</a>',
@@ -1535,15 +1534,13 @@ public static function tags_search() {
15351534
}
15361535
$s = trim( $s );
15371536

1538-
/**
1539-
* This filter has been defined in /wp-admin/includes/ajax-actions.php
1540-
*/
1537+
/** This filter has been defined in /wp-admin/includes/ajax-actions.php */
15411538
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
15421539

15431540
/*
1544-
* Require $term_search_min_chars chars for matching (default: 2)
1545-
* ensure it's a non-negative, non-zero integer.
1546-
*/
1541+
* Require $term_search_min_chars chars for matching (default: 2)
1542+
* ensure it's a non-negative, non-zero integer.
1543+
*/
15471544
if ( ( 0 === $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) {
15481545
wp_die();
15491546
}
@@ -1575,13 +1572,13 @@ public static function settings_page_header() {
15751572
?>
15761573
<p>
15771574
<a class="crp_button crp_button_green" href="<?php echo esc_url( admin_url( 'tools.php?page=crp_tools_page' ) ); ?>">
1578-
<?php esc_html_e( 'Visit the Tools page', 'contextual-related-posts' ); ?>
1575+
<?php esc_html_e( 'Visit the Tools page', 'contextual-related-posts' ); ?>
15791576
</a>
1580-
<?php if ( ! $crp_freemius->is_paying() ) { ?>
1577+
<?php if ( ! $crp_freemius->is_paying() ) { ?>
15811578
<a class="crp_button crp_button_gold" href="<?php echo esc_url( $crp_freemius->get_upgrade_url() ); ?>">
1582-
<?php esc_html_e( 'Upgrade to Pro', 'contextual-related-posts' ); ?>
1579+
<?php esc_html_e( 'Upgrade to Pro', 'contextual-related-posts' ); ?>
15831580
</a>
1584-
<?php } ?>
1581+
<?php } ?>
15851582
</p>
15861583

15871584
<?php
@@ -1590,8 +1587,8 @@ public static function settings_page_header() {
15901587
/**
15911588
* Updated the settings fields to display a pro version link.
15921589
*
1593-
* @param string $output Settings field HTML.
1594-
* @param array $args Settings field arguments.
1590+
* @param string $output Settings field HTML.
1591+
* @param array $args Settings field arguments.
15951592
* @return string Updated HTML.
15961593
*/
15971594
public static function after_setting_output( $output, $args ) {

includes/admin/settings/class-metabox-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function sanitize_post_meta( $settings ) {
353353
$ids = array();
354354
$names = array();
355355

356-
$taxes = array_unique( str_getcsv( $settings[ $key ] ) );
356+
$taxes = array_unique( str_getcsv( $settings[ $key ], ',', '"', '\\' ) );
357357

358358
foreach ( $taxes as $tax ) {
359359
$tax_name = get_term_by( 'name', $tax, $fields['tax'] );

includes/admin/settings/class-settings-api.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ public function add_custom_menu_page( $menu ) {
416416
* Add admin menu.
417417
*/
418418
public function admin_menu() {
419-
global ${$this->prefix . '_menu_pages'};
420-
421419
foreach ( $this->menus as $menu ) {
422420
$menu_page = $this->add_custom_menu_page( $menu );
423421

@@ -426,7 +424,6 @@ public function admin_menu() {
426424
$this->settings_page = $menu_page;
427425
}
428426
}
429-
${$this->prefix . '_menu_pages'} = $this->menu_pages;
430427

431428
// Load the settings contextual help.
432429
add_action( 'load-' . $this->settings_page, array( $this, 'settings_help' ) );

includes/admin/settings/class-settings-sanitize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static function str_putcsv( $input_array, $delimiter = ',', $enclosure =
262262
*/
263263
public static function sanitize_tax_slugs( &$settings, $source_key, $target_key ) {
264264
if ( isset( $settings[ $source_key ] ) ) {
265-
$slugs = array_unique( str_getcsv( $settings[ $source_key ] ) );
265+
$slugs = array_unique( str_getcsv( $settings[ $source_key ], ',', '"', '\\' ) );
266266

267267
foreach ( $slugs as $slug ) {
268268
// Pattern is Name (taxonomy:term_taxonomy_id).

phpcs.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@
3838
<rule ref="Generic.Commenting.Todo"/>
3939
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed"/>
4040

41+
<!-- Check for PHP 7.4+ compatibility. -->
42+
<config name="testVersion" value="7.4-"/>
43+
<rule ref="PHPCompatibilityWP"/>
44+
4145
</ruleset>

0 commit comments

Comments
 (0)