-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
380 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
|
||
/** | ||
* @package WP Subtitle | ||
* @subpackage WooCommerce | ||
* | ||
* @since 3.1 | ||
* | ||
* Compatibility for the WooCommerce plugin: | ||
* https://wordpress.org/plugins/woocommerce/ | ||
*/ | ||
|
||
class WPSubtitle_WooCommerce { | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @since 3.1 | ||
* | ||
* @internal Do not create multiple instances. | ||
*/ | ||
public function __construct() { | ||
|
||
if ( 'yes' == get_option( 'wp_subtitle_woocommerce_enabled' ) ) { | ||
|
||
add_action( 'init', array( $this, 'add_product_post_type_support' ) ); | ||
|
||
if ( 'yes' == get_option( 'wp_subtitle_woocommerce_show_on_single' ) ) { | ||
add_action( 'woocommerce_single_product_summary' , array( $this, 'single_product_summary' ), 6 ); | ||
} | ||
|
||
if ( 'yes' == get_option( 'wp_subtitle_woocommerce_show_in_loop' ) ) { | ||
add_action( 'woocommerce_shop_loop_item_title' , array( $this, 'shop_loop_item_title' ) ); | ||
} | ||
|
||
} | ||
|
||
add_filter( 'woocommerce_product_settings' , array( $this, 'product_settings' ) ); | ||
|
||
} | ||
|
||
/** | ||
* Add Product Post Type Support | ||
* | ||
* @since 3.1 | ||
* | ||
* @internal Private. Called via the `init` action. | ||
*/ | ||
public function add_product_post_type_support() { | ||
|
||
add_post_type_support( 'product', 'wps_subtitle' ); | ||
|
||
} | ||
|
||
/** | ||
* Single Product Summary | ||
* | ||
* @since 3.1 | ||
* | ||
* @internal Private. Called via the `woocommerce_single_product_summary` action. | ||
*/ | ||
public function single_product_summary() { | ||
|
||
the_subtitle( '<h2 class="product_subtitle entry-subtitle wp-subtitle">', '</h2>' ); | ||
|
||
} | ||
|
||
/** | ||
* Shop Loop Item Title | ||
* | ||
* @since 3.1 | ||
* | ||
* @internal Private. Called via the `woocommerce_shop_loop_item_title` action. | ||
*/ | ||
public function shop_loop_item_title() { | ||
|
||
the_subtitle( '<p class="woocommerce-loop-product__subtitle wp-subtitle">', '</p>' ); | ||
|
||
} | ||
|
||
/** | ||
* Product Settings | ||
* | ||
* @since 3.1 | ||
* | ||
* @param array $settings Settings. | ||
* @return array Settings. | ||
* | ||
* @internal Private. Called via the `woocommerce_product_settings` filter. | ||
*/ | ||
public function product_settings( $settings ) { | ||
|
||
$subtitle_settings = array( | ||
|
||
array( | ||
'title' => __( 'WP Subtitle', 'wp-subtitle' ), | ||
'type' => 'title', | ||
'desc' => '', | ||
'id' => 'wp_subtitle_options' | ||
), | ||
|
||
array( | ||
'title' => __( 'Enable Product Subtitles', 'wp-subtitle' ), | ||
'desc' => __( 'Add subtitle field to product edit screen', 'wp-subtitle' ), | ||
'id' => 'wp_subtitle_woocommerce_enabled', | ||
'default' => 'no', | ||
'type' => 'checkbox', | ||
), | ||
|
||
array( | ||
'title' => __( 'Subtitle Display', 'wp-subtitle' ), | ||
'desc' => __( 'Show on single product pages', 'wp-subtitle' ), | ||
'id' => 'wp_subtitle_woocommerce_show_on_single', | ||
'default' => 'yes', | ||
'type' => 'checkbox', | ||
'checkboxgroup' => 'start' | ||
), | ||
|
||
array( | ||
'desc' => __( 'Show on product archives', 'wp-subtitle' ), | ||
'id' => 'wp_subtitle_woocommerce_show_in_loop', | ||
'default' => 'yes', | ||
'type' => 'checkbox', | ||
'checkboxgroup' => 'end' | ||
), | ||
|
||
array( | ||
'type' => 'sectionend', | ||
'id' => 'wp_subtitle_options' | ||
) | ||
|
||
); | ||
|
||
return array_merge( $settings, $subtitle_settings ); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* @package WP Subtitle | ||
* @subpackage WordPress SEO | ||
* | ||
* @since 3.1 | ||
* | ||
* Compatibility for the Yoast SEO plugin: | ||
* https://wordpress.org/plugins/wordpress-seo/ | ||
* | ||
* Adds support for a `%%wps_subtitle%%` placeholder to include | ||
* the subtitle in browser titles and meta descriptions. | ||
* | ||
* Also adds `%%wps_subtitle_before_sep%%` and `%%wps_subtitle_after_sep%%`. | ||
* These can be used to add seperators before/after the subtitle. If there | ||
* is no subtitle set these placeholders will not be output. | ||
* | ||
* The seperator placeholders can be customized using the `wps_subtitle_seo_before_sep` | ||
* and `wps_subtitle_seo_after_sep` filters. | ||
* | ||
* The seperator placeholders include a 'space' either side by default. This means that | ||
* you should create your title template with no whitespace around the seperator placeholders. | ||
* It allows you to customize the seperators to include commas and butt the seperator up to | ||
* the preceding/following text. | ||
* | ||
* e.g. If '%%wps_subtitle_before_sep%%' is set to ', ': | ||
* `%%title%%%%wps_subtitle_before_sep%%%%wps_subtitle%% %%sep%% %%sitename%%` | ||
* "Title, Subtitle - Sitename" | ||
*/ | ||
|
||
class WPSubtitle_WPSEO { | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @since 3.1 | ||
* | ||
* @internal Do not create multiple instances. | ||
*/ | ||
public function __construct() { | ||
|
||
add_filter( 'wpseo_replacements', array( $this, 'add_wpseo_replacements' ) ); | ||
|
||
} | ||
|
||
/** | ||
* Add SEO Replacements | ||
* | ||
* @since 3.1 | ||
* | ||
* @param array $replacements SEO replacements. | ||
* @return array Filtered replacements. | ||
* | ||
* @internal Called via the `wpseo_replacements` filter. | ||
*/ | ||
public function add_wpseo_replacements( $replacements ) { | ||
|
||
global $post; | ||
|
||
$wp_subtitle = new WP_Subtitle( $post ); | ||
$subtitle = $wp_subtitle->get_subtitle(); | ||
|
||
$replacements['%%wps_subtitle%%'] = $subtitle; | ||
$replacements['%%wps_subtitle_before_sep%%'] = ''; | ||
$replacements['%%wps_subtitle_after_sep%%'] = ''; | ||
|
||
if ( ! empty( $subtitle ) ) { | ||
|
||
$sep = isset( $replacements['%%sep%%'] ) ? ' ' . $replacements['%%sep%%'] . ' ' : ' - '; | ||
|
||
$replacements['%%wps_subtitle_before_sep%%'] = apply_filters( 'wps_subtitle_seo_before_sep', $sep ); | ||
$replacements['%%wps_subtitle_after_sep%%'] = apply_filters( 'wps_subtitle_seo_after_sep', $sep ); | ||
|
||
} | ||
|
||
return $replacements; | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.