Skip to content

Commit

Permalink
Merge pull request #7 from davisshaver/add-image-button-to-manifest
Browse files Browse the repository at this point in the history
feat: add image url and button title to manifest
  • Loading branch information
davisshaver authored Dec 16, 2024
2 parents 5a52ec1 + f32652a commit 4fa4b9a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 29 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions farcaster-wp.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Plugin Name: Farcaster WP
* Plugin URI: https://farcaster-wp.davisshaver.com/
* Description: Farcaster WP connects your WordPress site to Farcaster.
* Version: 0.0.31
* Version: 0.0.32
* Author: Davis Shaver
* Author URI: https://davisshaver.com/
* License: GPL v2 or later
Expand All @@ -22,7 +22,7 @@

defined( 'ABSPATH' ) || exit;

define( 'FARCASTER_WP_VERSION', '0.0.31' );
define( 'FARCASTER_WP_VERSION', '0.0.32' );

define( 'FARCASTER_WP_API_NAMESPACE', 'farcaster-wp/v1' );
define( 'FARCASTER_WP_API_URL', get_site_url() . '/wp-json/' . FARCASTER_WP_API_NAMESPACE );
Expand Down
8 changes: 5 additions & 3 deletions includes/api/class-manifest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public function get_manifest() {
$splash_background_color = Frames::get_splash_background_color( $options );
$splash_image_url = Frames::get_splash_image_url( $options );
$domain_manifest = json_decode( $options['domain_manifest'], true );

$header = '';
$frame_image_url = Frames::get_frame_image_url( $options );
$button_title = Frames::get_button_text( $options );
$header = '';
if ( ! empty( $domain_manifest['accountAssociation']['header'] ) ) {
$header = $domain_manifest['accountAssociation']['header'];
} elseif ( ! empty( $domain_manifest['header'] ) ) {
Expand Down Expand Up @@ -101,7 +102,8 @@ public function get_manifest() {
'iconUrl' => get_site_icon_url(),
'splashImageUrl' => $splash_image_url,
'splashBackgroundColor' => $splash_background_color,

'imageUrl' => $frame_image_url,
'buttonTitle' => $button_title,
],
];

Expand Down
37 changes: 30 additions & 7 deletions includes/class-frames.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ public static function get_splash_image_url( $options ) {
return '';
}

/**
* Get frame image URL from settings.
*
* @param array $options Plugin options.
* @return string Frame image URL or empty string if not set.
*/
public static function get_frame_image_url( $options ) {
$frame_image = $options['fallback_image'] ?? '';

if ( ! empty( $frame_image ) && ! empty( $frame_image['id'] ) ) {
$frame_image_src = wp_get_attachment_image_src( $frame_image['id'], 'farcaster-wp-frame-image' );
if ( ! empty( $frame_image_src ) ) {
return $frame_image_src[0];
}
}

return '';
}

/**
* Get button text from settings.
*
* @param array $options Plugin options.
* @return string Button text.
*/
public static function get_button_text( $options ) {
return $options['button_text'] ?? __( 'Read More', 'farcaster-wp' );
}

/**
* Get splash background color from settings.
*
Expand Down Expand Up @@ -86,13 +115,7 @@ public static function get_frame_data() {

$frame_image = is_singular() ? get_the_post_thumbnail_url( null, 'farcaster-wp-frame-image' ) : '';
if ( empty( $frame_image ) ) {
$fallback_image = $options['fallback_image'] ?? '';
if ( ! empty( $fallback_image ) && ! empty( $fallback_image['id'] ) ) {
$frame_image_src = wp_get_attachment_image_src( $fallback_image['id'], 'farcaster-wp-frame-image' );
if ( ! empty( $frame_image_src ) ) {
$frame_image = $frame_image_src[0];
}
}
$frame_image = self::get_frame_image_url( $options );
}

$url = is_singular() ? get_permalink() : home_url( $wp->request );
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "farcaster-wp",
"version": "0.0.31",
"version": "0.0.32",
"description": "Farcaster WP connects your WordPress site to Farcaster.",
"author": "Davis Shaver",
"license": "GPL-2.0-or-later",
Expand All @@ -17,8 +17,8 @@
"url": "https://github.com/davisshaver/farcaster-wp/issues"
},
"dependencies": {
"@farcaster/frame-sdk": "^0.0.16",
"@farcaster/frame-wagmi-connector": "^0.0.1",
"@farcaster/frame-sdk": "^0.0.18",
"@farcaster/frame-wagmi-connector": "^0.0.3",
"@tanstack/react-query": "^5.62.7",
"@types/react-dnd": "^3.0.2",
"@wagmi/core": "^2.16.0",
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: WordPress, web3, Farcaster, Ethereum
Tested up to: 6.7.1
Requires at least: 6.7.0
Requires PHP: 7.0
Stable tag: 0.0.31
Stable tag: 0.0.32
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -26,7 +26,7 @@ Farcaster WP makes it easy to setup [Farcaster frames](https://docs.farcaster.xy

== Changelog ==

= 0.0.31 =
= 0.0.32 =
* Initial plugin release to WordPress.org

== Screenshots =
Expand Down
19 changes: 13 additions & 6 deletions src/admin-components/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,22 @@ const TippingAmountsControl = ( { value = [], onChange } ) => {
);
};

const ButtonTextControl = ( { value, onChange } ) => {
const ButtonTextControl = ( { value, onChange, useTitleAsButtonText } ) => {
return (
<TextControl
label={ __( 'Button Text', 'farcaster-wp' ) }
value={ value }
help={ __(
'This text will be used as the button text for all posts. Limited to 32 characters.',
'farcaster-wp'
) }
help={
! useTitleAsButtonText
? __(
'This text will be used as the button text for all posts. Limited to 32 characters.',
'farcaster-wp'
)
: __(
'This text will be used as the button text when frame is used outside of casts. Limited to 32 characters.',
'farcaster-wp'
)
}
onChange={ onChange }
__nextHasNoMarginBottom
maxLength={ 32 }
Expand Down Expand Up @@ -364,7 +371,7 @@ const UseTitleAsButtonTextControl = ( { value, onChange } ) => {
return (
<ToggleControl
checked={ value }
label={ __( 'Use Title as Button Text', 'farcaster-wp' ) }
label={ __( 'Use Post Title as Button Text', 'farcaster-wp' ) }
onChange={ onChange }
__nextHasNoMarginBottom
/>
Expand Down
29 changes: 29 additions & 0 deletions src/admin-components/ManifestViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface ManifestMismatches {
name: boolean;
homeUrl: boolean;
iconUrl: boolean;
imageUrl: boolean;
buttonTitle: boolean;
splashImageUrl: boolean;
splashBackgroundColor: boolean;
webhookUrl?: boolean;
Expand Down Expand Up @@ -74,6 +76,11 @@ const ManifestViewer = ( {
splashBackgroundColor:
manifest?.frame?.splashBackgroundColor !==
currentManifest?.frame?.splashBackgroundColor,
buttonTitle:
manifest?.frame?.buttonTitle !==
currentManifest?.frame?.buttonTitle,
imageUrl:
manifest?.frame?.imageUrl !== currentManifest?.frame?.imageUrl,
...( currentManifest?.frame?.webhookUrl
? {
webhookUrl:
Expand Down Expand Up @@ -287,6 +294,28 @@ const ManifestViewer = ( {
) }
</Notice>
) }
{ mismatches.details.imageUrl && (
<Notice
status="warning"
isDismissible={ false }
>
{ __(
'The manifest image URL does not match the current site image URL.',
'farcaster-wp'
) }
</Notice>
) }
{ mismatches.details.buttonTitle && (
<Notice
status="warning"
isDismissible={ false }
>
{ __(
'The manifest button title does not match the current site button title.',
'farcaster-wp'
) }
</Notice>
) }
{ mismatches.details.splashImageUrl && (
<Notice
status="warning"
Expand Down
11 changes: 5 additions & 6 deletions src/admin-components/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ const SettingsPage = () => {
value={ useTitleAsButtonText }
onChange={ setUseTitleAsButtonText }
/>
{ useTitleAsButtonText !== true && (
<ButtonTextControl
value={ buttonText }
onChange={ setButtonText }
/>
) }
<ButtonTextControl
useTitleAsButtonText={ useTitleAsButtonText }
value={ buttonText }
onChange={ setButtonText }
/>
</VStack>
</PanelRow>
</PanelBody>
Expand Down
14 changes: 14 additions & 0 deletions src/admin-utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ const FrameConfigSchema = z.object( {
message: 'Splash image URL must be 512 characters or less',
} )
.optional(),
imageUrl: z
.string( {
invalid_type_error: 'Image URL must be a string',
required_error: 'Image URL is required',
} )
.max( 512, {
message: 'Splash image URL must be 512 characters or less',
} ),
buttonTitle: z
.string( {
invalid_type_error: 'Button title must be a string',
required_error: 'Button title is required',
} )
.max( 32, { message: 'Button title must be 32 characters or less' } ),
splashBackgroundColor: z
.string( {
invalid_type_error: 'Splash background color must be a string',
Expand Down

0 comments on commit 4fa4b9a

Please sign in to comment.