Skip to content

Commit

Permalink
V1.7.3
Browse files Browse the repository at this point in the history
PHP 7.4 and WP 6.2 are now required. This is to use the new [WP_HTML_Tag_Processor](https://make.wordpress.org/core/2023/03/07/introducing-the-html-api-in-wordpress-6-2/) functions.
Fixed a bug where classes were overridden.
  • Loading branch information
janw-me committed Apr 7, 2023
1 parent 8a2a8fa commit eb808fd
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 113 deletions.
1 change: 0 additions & 1 deletion .phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
*/
define( 'DFI_VERSION', 'string');
define( 'DFI_DIR', 'string');
define( 'DFI_APP_DIR', 'string');
define( 'DFI_URL', 'string');
define( 'DFI_NAME', 'string');
21 changes: 12 additions & 9 deletions app/class-dfi.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,28 @@ public function add_settings_link( $links ) {
public function show_dfi( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$default_thumbnail_id = get_option( 'dfi_image_id' ); // select the default thumb.

// if an image is set return that image.
// If an image is set return that image.
if ( (int) $default_thumbnail_id !== (int) $post_thumbnail_id ) {
return $html;
}

// Attributes can be a query string, parse that.
if ( is_string( $attr ) ) {
wp_parse_str( $attr, $attr );
}

if ( isset( $attr['class'] ) ) {
// There already are classes, we trust those.
$attr['class'] .= ' default-featured-img';
} else {
$size_class = $size;
if ( is_array( $size_class ) ) {
$size_class = 'size-' . implode( 'x', $size_class );
// No classes in the attributes, try to get them form the HTML.
$img = new \WP_HTML_Tag_Processor( $html );
if ( $img->next_tag() ) {
$attr['class'] = trim( $img->get_attribute( 'class' ) . ' default-featured-img' );
}
// attachment-$size is a default class `wp_get_attachment_image` would otherwise add. It won't add it if there are classes already there.
$attr = array( 'class' => "attachment-{$size_class} default-featured-img" );
}

$html = wp_get_attachment_image( $default_thumbnail_id, $size, false, $attr );
$html = apply_filters( 'dfi_thumbnail_html', $html, $post_id, $default_thumbnail_id, $size, $attr );

return $html;
return apply_filters( 'dfi_thumbnail_html', $html, $post_id, $default_thumbnail_id, $size, $attr );
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
"createzip-with-version": "Will create a zip named 'plugin-slug-0.1.0.zip' in the Downloads folder."
},
"require": {
"php": ">=7.0"
"php": ">=7.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5.2",
"wp-coding-standards/wpcs": "^2.2.0",
"phpcompatibility/phpcompatibility-wp": "^2.1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"szepeviktor/phpstan-wordpress": "^1.0",
"php-parallel-lint/php-parallel-lint": "^1.2"
},
Expand Down
96 changes: 50 additions & 46 deletions composer.lock

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

41 changes: 4 additions & 37 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,8 @@

<description>DFI phpCS</description>

<!--
This is a sample ruleset which can be used as a starting point for a PHPCS ruleset for a WordPress project.
Whether you are reviewing other people's code or working on your own code, it is useful to
have such a ruleset in place to:
- Document the settings used both for your future self as well as for other contributors to the project.
- Ensure that everyone uses the same settings when reviewing the code.
- Make life easier as you no longer will have to type in a long range of command line parameters.
Before you use this ruleset, make sure to customize the following:
- The ruleset name and description above.
- The supported PHP versions as set in the value for `testVersion`.
For information on how to set the value for `testVersion`, please see:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions
- The minimum supported WP version `minimum_supported_wp_version`.
For more information about this setting, see:
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#minimum-wp-version-to-check-for-usage-of-deprecated-functions-classes-and-function-parameters
- The `text-domain` used by the project.
For more information about this setting, see:
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#internationalization-setting-your-text-domain
- The `prefixes` used by the project.
For more information about this setting, see:
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace
-->

<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
#############################################################################
-->

<file>.</file>

<exclude-pattern>node_modules/*</exclude-pattern>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>.support/*</exclude-pattern>
<file>./app</file>
<file>./set-default-featured-image.php</file>

<!-- Only check PHP files. -->
<arg name="extensions" value="php"/>
Expand All @@ -64,7 +31,7 @@
<exclude name="Squiz.Commenting.FileComment.Missing"/>
</rule>

<config name="testVersion" value="5.6-"/>
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibilityWP"/>

<!--
Expand All @@ -74,7 +41,7 @@
-->

<!-- Set the minimum supported WP version. This is used by several sniffs. -->
<config name="minimum_supported_wp_version" value="5.2"/>
<config name="minimum_supported_wp_version" value="6.2"/>

<!-- Verify that all gettext calls use the correct text domain. -->
<rule ref="WordPress.WP.I18n">
Expand Down
Loading

0 comments on commit eb808fd

Please sign in to comment.