Skip to content

Commit e61b0c9

Browse files
refactor: replace Composer dependency with WordPress fetch_feed()
- Remove yuzuru-s/parse-rss and use WordPress built-in fetch_feed() (SimplePie) - Remove composer.json, composer.lock, and vendor/ from .gitignore - Remove composer install step from release workflow - Remove vendor/* from release archive - Add error handling for feed fetch failures Co-Authored-By: yoshiko@digitalcube.jp <yoshiko@digitalcube.jp>
1 parent e086bf5 commit e61b0c9

5 files changed

Lines changed: 27 additions & 213 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ jobs:
1515
steps:
1616
- uses: actions/checkout@v4
1717

18-
- name: composer install
19-
run: composer install --no-dev --prefer-dist --no-progress --no-interaction
20-
2118
- name: get tag name
2219
id: tag
2320
run: echo "tagname=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
@@ -27,7 +24,7 @@ jobs:
2724

2825
- name: create archive
2926
env:
30-
FILES_TO_ARCHIVE: "*.php *.md LICENSE vendor/*"
27+
FILES_TO_ARCHIVE: "*.php *.md LICENSE"
3128
run: zip -r ${PACKAGE_NAME}.zip ${FILES_TO_ARCHIVE}
3229

3330
- name: upload to github release
@@ -36,3 +33,4 @@ jobs:
3633
tag_name: ${{ steps.tag.outputs.tagname }}
3734
name: "${{ env.PACKAGE_NAME }} ${{ steps.tag.outputs.tagname }}"
3835
files: ${{ env.PACKAGE_NAME }}.zip
36+

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
vendor/
2-
*.zip
1+
*.zip

composer.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

composer.lock

Lines changed: 0 additions & 179 deletions
This file was deleted.

shifter-github-hosting-plugin-sample.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,39 @@
88
Author URI: https://getshifter.io/
99
*/
1010

11-
$shifter_github_hosting_autoload = __DIR__ . '/vendor/autoload.php';
12-
13-
if ( ! file_exists( $shifter_github_hosting_autoload ) ) {
14-
add_action( 'admin_notices', function() {
15-
printf(
16-
'<div class="notice notice-error"><p>%s</p></div>',
17-
esc_html__( 'Shifter GitHub hosting plugin sample requires Composer dependencies. Please run "composer install" in the plugin directory, or install the plugin from a GitHub Release zip.', 'shifter-github-hosting-plugin-sample' )
18-
);
19-
});
20-
return;
21-
}
22-
23-
require $shifter_github_hosting_autoload;
24-
2511
add_action( 'admin_notices', function() {
2612
// get Shifter News
2713
$transient_key = 'shifter-news-posts';
28-
if (false === ($posts = get_transient($transient_key))) {
29-
$url = 'https://www.getshifter.io/feed/';
30-
$res = YuzuruS\Rss\Feed::load($url);
31-
14+
if ( false === ( $posts = get_transient( $transient_key ) ) ) {
15+
$url = 'https://www.getshifter.io/feed/';
16+
$feed = fetch_feed( $url );
17+
18+
if ( is_wp_error( $feed ) ) {
19+
return;
20+
}
21+
22+
$items = $feed->get_items( 0, 10 );
3223
$posts = [];
33-
foreach ($res['item'] as $r) {
24+
foreach ( $items as $item ) {
3425
$posts[] = sprintf(
3526
'<a href="%s" title="%s">%s</a>',
36-
esc_url_raw($r['link']),
37-
esc_attr($r['title']),
38-
$r['title']
27+
esc_url_raw( $item->get_permalink() ),
28+
esc_attr( $item->get_title() ),
29+
$item->get_title()
3930
);
4031
}
41-
set_transient($transient_key, $posts, HOUR_IN_SECONDS);
32+
33+
if ( empty( $posts ) ) {
34+
return;
35+
}
36+
37+
set_transient( $transient_key, $posts, HOUR_IN_SECONDS );
4238
}
39+
40+
if ( empty( $posts ) ) {
41+
return;
42+
}
43+
4344
$shifter_news = $posts[ mt_rand( 0, count( $posts ) - 1 ) ];
4445

4546
printf(

0 commit comments

Comments
 (0)