Skip to content

Commit

Permalink
Classic Theme Helper: Copy Testimonials Custom Post Type code to Clas…
Browse files Browse the repository at this point in the history
…sic Theme Helper package (#40295)
  • Loading branch information
coder-karen authored Nov 26, 2024
1 parent 9a5997a commit 63a223a
Show file tree
Hide file tree
Showing 7 changed files with 1,722 additions and 763 deletions.
5 changes: 3 additions & 2 deletions projects/packages/classic-theme-helper/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
return [
// # Issue statistics:
// PhanUndeclaredClassMethod : 20+ occurrences
// PhanTypeMismatchArgumentInternal : 10+ occurrences
// PhanUndeclaredClassMethod : 10+ occurrences
// PhanTypePossiblyInvalidDimOffset : 8 occurrences
// PhanTypeMismatchArgumentProbablyReal : 5 occurrences
// PhanUndeclaredClassReference : 4 occurrences
// PhanTypeMismatchArgumentProbablyReal : 3 occurrences
// PhanTypeSuspiciousNonTraversableForeach : 3 occurrences
// PhanTypeInvalidDimOffset : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
Expand All @@ -29,6 +29,7 @@
'src/content-options/featured-images-fallback.php' => ['PhanTypePossiblyInvalidDimOffset'],
'src/custom-content-types.php' => ['PhanUndeclaredClassMethod'],
'src/custom-post-types/class-jetpack-portfolio.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredClassMethod'],
'src/custom-post-types/class-jetpack-testimonial.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredClassMethod'],
'src/site-breadcrumbs.php' => ['PhanUndeclaredClassMethod'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Classic Theme Helper: Adding Testimonial custom post type content
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Helper class for the Jetpack Testimonial Textarea Control.
*
* @package automattic/jetpack-classic-theme-helper
*/

namespace Automattic\Jetpack\Classic_Theme_Helper;

if ( ! class_exists( __NAMESPACE__ . '\Jetpack_Testimonial_Textarea_Control' ) ) {
/**
* Extends the WP_Customize_Control class to clean the textarea content.
*/
class Jetpack_Testimonial_Textarea_Control extends \WP_Customize_Control {
/**
* Control type.
*
* @var string
*/
public $type = 'textarea';

/**
* Render the control's content.
*/
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}

/**
* Sanitize content passed to control.
*
* @param string $value Control value.
* @return string Sanitized value.
*/
public static function sanitize_content( $value ) {
if ( ! empty( $value ) ) {
$value = apply_filters( 'the_content', $value );
}
$value = preg_replace( '@<div id="jp-post-flair"([^>]+)?>(.+)?</div>@is', '', $value );
return $value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Helper class for the Jetpack Testimonial Title Control.
*
* @package automattic/jetpack-classic-theme-helper
*/

namespace Automattic\Jetpack\Classic_Theme_Helper;

if ( ! class_exists( __NAMESPACE__ . '\Jetpack_Testimonial_Title_Control' ) ) {
/**
* Extends the WP_Customize_Control class to clean the title parameter.
*/
class Jetpack_Testimonial_Title_Control extends \WP_Customize_Control {
/**
* Sanitize content passed to control.
*
* @param string $value Control value.
* @return string Sanitized value.
*/
public static function sanitize_content( $value ) {
if ( '' != $value ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- handle non-string inputs gracefully.
$value = trim( convert_chars( wptexturize( $value ) ) );
}
return $value;
}
}
}
Loading

0 comments on commit 63a223a

Please sign in to comment.