Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-17: add url override to post block #42

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions blocks/post/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"type": "string",
"default": ""
},
"overrideUrl": {
"type": "string",
"default": ""
},
"number": {
"type": "number",
"default": null
Expand Down
16 changes: 16 additions & 0 deletions blocks/post/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PanelBody,
PanelRow,
Spinner,
TextControl,
} from '@wordpress/components';

/**
Expand Down Expand Up @@ -45,6 +46,7 @@ interface EditProps {
overrideExcerpt?: string;
overrideContent?: string;
overrideByline?: string;
overrideUrl?: string,
number?: number;
smallerFont?: boolean;
},
Expand Down Expand Up @@ -73,6 +75,7 @@ export default function Edit({
overrideExcerpt,
overrideContent,
overrideByline,
overrideUrl,
number,
smallerFont,
},
Expand All @@ -85,6 +88,7 @@ export default function Edit({
overrideImage: 0,
overrideExcerpt: '',
overrideContent: '',
overrideUrl: '',
});
};

Expand Down Expand Up @@ -287,6 +291,18 @@ export default function Edit({
/>
</PanelRow>
</PanelBody>
<PanelBody
title={__('Override URL', 'wp-newsletter-builder')}
initialOpen
>
<PanelRow>
<TextControl
value={overrideUrl ?? ''}
onChange={(newValue: string) => setAttributes({ overrideUrl: newValue })}
type="url"
/>
</PanelRow>
</PanelBody>
</InspectorControls>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions blocks/post/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
}
$wp_newsletter_builder_post_title = ! empty( $attributes['overrideTitle'] ) ? $attributes['overrideTitle'] : $wp_newsletter_builder_block_post->post_title;
$wp_newsletter_builder_post_image = ! empty( $attributes['overrideImage'] ) ? $attributes['overrideImage'] : get_post_thumbnail_id( $wp_newsletter_builder_block_post->ID );
$wp_newsletter_builder_post_url = ! empty( $attributes['overrideUrl'] ) ? $attributes['overrideUrl'] : get_permalink( $wp_newsletter_builder_block_post->ID );
$wp_newsletter_builder_excerpt = ! empty( $attributes['overrideExcerpt'] ) ? $attributes['overrideExcerpt'] : $wp_newsletter_builder_block_post->post_excerpt;
$wp_newsletter_builder_content = $wp_newsletter_builder_block_post->post_content;
preg_match_all( '/<p.*?<\/p>/iU', $wp_newsletter_builder_content, $matches );
Expand Down Expand Up @@ -50,7 +51,7 @@
switch ( $wp_newsletter_builder_item ) {
case 'title':
?>
<a class="post__title-link" href="<?php echo esc_url( get_permalink( $wp_newsletter_builder_block_post->ID ) ); ?>">
<a class="post__title-link" href="<?php echo esc_url( $wp_newsletter_builder_post_url ); ?>">
<h2 class="<?php echo esc_attr( $wp_newsletter_builder_title_class ); ?>">
<?php if ( ! empty( $wp_newsletter_builder_number ) ) : ?>
<span class="newsletter-post__number"><?php echo esc_html( $wp_newsletter_builder_number ); ?>.</span>
Expand Down Expand Up @@ -82,7 +83,7 @@
case 'image':
?>
<?php if ( $wp_newsletter_builder_showimage && ! empty( $wp_newsletter_builder_post_image ) ) : ?>
<a class="post__image-link" href="<?php echo esc_url( get_permalink( $wp_newsletter_builder_block_post->ID ) ); ?>">
<a class="post__image-link" href="<?php echo esc_url( $wp_newsletter_builder_post_url ); ?>">
<?php echo wp_get_attachment_image( $wp_newsletter_builder_post_image, 'full', false, [ 'sizes' => $wp_newsletter_builder_img_sizes ] ); ?>
</a>
<?php
Expand All @@ -109,11 +110,11 @@
<?php if ( $wp_newsletter_builder_showcta ) : ?>
<div class="wp-block-button has-text-align-center">
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="<?php echo esc_url( get_permalink( $wp_newsletter_builder_block_post->ID ) ); ?>" style="height:48px;v-text-anchor:middle;width:200px;" arcsize="10%" stroke="f" fillcolor="#D62827">
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="<?php echo esc_url( $wp_newsletter_builder_post_url ); ?>" style="height:48px;v-text-anchor:middle;width:200px;" arcsize="10%" stroke="f" fillcolor="#D62827">
<w:anchorlock/>
<center>
<![endif]-->
<a class="wp-element-button" href="<?php echo esc_url( get_permalink( $wp_newsletter_builder_block_post->ID ) ); ?>">
<a class="wp-element-button" href="<?php echo esc_url( $wp_newsletter_builder_post_url ); ?>">
<?php esc_html_e( 'Read More', 'wp-newsletter-builder' ); ?>
</a>
<!--[if mso]>
Expand Down