Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit c7fba0c

Browse files
committed
feat(media): strip size from thumbnails
1 parent 5905d7b commit c7fba0c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

command.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function codeat_get_by_url( $args ){
2424

2525
$hasext = pathinfo( $url, PATHINFO_EXTENSION );
2626
if ( !empty( $hasext ) ) {
27+
$url = preg_replace( "/^(.+)-\d+?x\d+?(\.\w+)$/i","$1$2", $url );
2728
$media = attachment_url_to_postid( $url );
2829
if ( $media !== 0 ) {
2930
WP_CLI::log( 'media | ' . $media . ' | attachment' );
@@ -43,12 +44,14 @@ function codeat_get_by_url( $args ){
4344
$term_slug = $url_parameters[ 0 ];
4445

4546
$taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' );
46-
foreach ( $taxonomies as $taxonomy ) {
47-
if ( $taxonomy->rewrite[ 'slug' ] === $term_slug ) {
48-
$tax = get_term_by( 'slug', $last_slug, $taxonomy->name );
49-
if( is_object( $tax ) ) {
50-
WP_CLI::log( 'term | ' . $tax->term_id . ' | ' . $tax->taxonomy );
51-
return;
47+
if ( is_array( $taxonomies ) ) {
48+
foreach ( $taxonomies as $taxonomy ) {
49+
if ( $taxonomy->rewrite[ 'slug' ] === $term_slug ) {
50+
$tax = get_term_by( 'slug', $last_slug, $taxonomy->name );
51+
if( is_object( $tax ) ) {
52+
WP_CLI::log( 'term | ' . $tax->term_id . ' | ' . $tax->taxonomy );
53+
return;
54+
}
5255
}
5356
}
5457
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeatcode/get-by-url",
3-
"description": "Get the id and post type or taxonomy by the url",
3+
"description": "Get the id of post types, taxonomies or media by the url",
44
"type": "wp-cli-package",
55
"homepage": "https://github.com/codeatcode",
66
"authors": [],
@@ -10,6 +10,6 @@
1010
},
1111
"require": {
1212
"wp-cli/wp-cli": ">=2.0.0",
13-
"php":">=5.4"
13+
"php":">=7.0"
1414
}
1515
}

0 commit comments

Comments
 (0)