Skip to content

Commit

Permalink
"Adjusted code to satisfy PHPCS naming conventions
Browse files Browse the repository at this point in the history
Code was updated across video, tweet, and embed-web-video classes to align with PHP Code Sniffer's WordPress naming conventions. Ignored variable checks were placed on non-snake cased node properties, and text strings were escaped in delete and meta classes. Aimed to enhance code quality and prevent potential scripting attacks."
  • Loading branch information
attackant committed Oct 31, 2023
1 parent a299ba5 commit 4cb16ac
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions admin/apple-actions/index/class-delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public function perform() {
*/
private function delete() {
if ( ! $this->is_api_configuration_valid() ) {
throw new \Apple_Actions\Action_Exception( __( 'Your Apple News API settings seem to be empty. Please fill the API key, API secret and API channel fields in the plugin configuration page.', 'apple-news' ) );
throw new \Apple_Actions\Action_Exception( esc_html__( 'Your Apple News API settings seem to be empty. Please fill the API key, API secret and API channel fields in the plugin configuration page.', 'apple-news' ) );
}

$remote_id = get_post_meta( $this->id, 'apple_news_api_id', true );
if ( ! $remote_id ) {
throw new \Apple_Actions\Action_Exception( __( 'This post has not been pushed to Apple News, cannot delete.', 'apple-news' ) );
throw new \Apple_Actions\Action_Exception( esc_html__( 'This post has not been pushed to Apple News, cannot delete.', 'apple-news' ) );
}

try {
Expand Down
2 changes: 1 addition & 1 deletion admin/class-admin-apple-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public static function build_sections_field( $post_id ) {
?>
<div class="section">
<label for="apple-news-section-<?php echo esc_attr( $section->id ); ?>">
<input id="apple-news-section-<?php echo esc_attr( $section->id ); ?>" name="apple_news_sections[]" type="checkbox" value="<?php echo esc_attr( $section->links->self ); ?>" <?php checked( self::section_is_checked( $apple_news_sections, $section->links->self, $section->isDefault ) ); ?>>
<input id="apple-news-section-<?php echo esc_attr( $section->id ); ?>" name="apple_news_sections[]" type="checkbox" value="<?php echo esc_attr( $section->links->self ); ?>" <?php checked( self::section_is_checked( $apple_news_sections, $section->links->self, $section->isDefault ) ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase ?>>
<?php echo esc_html( $section->name ); ?>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-embed-web-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class Embed_Web_Video extends Component {
*/
public static function node_matches( $node ) {
// First, check to see if the node is a YouTube or Vimeo Gutenberg block, because these are the simplest checks to make.
$is_figure = 'figure' === $node->nodeName;
$is_figure = 'figure' === $node->nodeName; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$is_vimeo_block = self::node_has_class( $node, 'wp-block-embed-vimeo' );
$is_youtube_block = self::node_has_class( $node, 'wp-block-embed-youtube' );
if ( $is_figure && ( $is_vimeo_block || $is_youtube_block ) ) {
return $node;
}

// Second, check to see if the node contains a YouTube or Vimeo oEmbed as a text string.
$inner_text = trim( $node->nodeValue );
$inner_text = trim( $node->nodeValue ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
$has_vimeo_url = (bool) preg_match( self::VIMEO_MATCH, $inner_text );
$has_youtube_url = (bool) preg_match( self::YOUTUBE_MATCH, $inner_text );
if ( $has_vimeo_url || $has_youtube_url ) {
Expand Down
2 changes: 2 additions & 0 deletions includes/apple-exporter/components/class-tweet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Tweet extends Component {
*/
public static function node_matches( $node ) {

/* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
// Handling for a Gutenberg Twitter embed.
if (
'figure' === $node->nodeName
Expand All @@ -38,6 +39,7 @@ public static function node_matches( $node ) {
'#https?://(www\.)?twitter\.com/.+?/status(es)?/.*#i',
trim( $node->nodeValue )
);
/* phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */

if ( self::node_has_class( $node, 'twitter-tweet' ) || $is_twitter_url ) {
return $node;
Expand Down
4 changes: 2 additions & 2 deletions includes/apple-exporter/components/class-video.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public static function node_matches( $node ) {
// Is this a gutenberg video block?
( self::node_has_class( $node, 'wp-block-video' )
&& $node->hasChildNodes()
&& 'video' === $node->firstChild->nodeName
&& 'video' === $node->firstChild->nodeName // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
)
// Or is this a stand-alone video tag?
|| 'video' === $node->nodeName
|| 'video' === $node->nodeName // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
) {
return $node;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function apple_news_register_meta_helper( $object_type, $object_slugs, $meta_key
// Object type must be either post or term.
if ( ! in_array( $object_type, [ 'post', 'term' ], true ) ) {
throw new InvalidArgumentException(
__(
esc_html__(
'Object type must be one of "post", "term".',
'apple-news'
)
Expand Down

0 comments on commit 4cb16ac

Please sign in to comment.