Skip to content

Commit 21eb672

Browse files
Merge pull request #2240 from ahmedkaludi/1.40
1.40
2 parents 29c5978 + 9e400d0 commit 21eb672

12 files changed

+183
-48
lines changed

admin_section/common-function.php

Lines changed: 107 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,14 +3242,15 @@ function saswp_validate_date($date, $format = 'Y-m-d H:i:s'){
32423242

32433243
function saswp_format_date_time($date, $time=null){
32443244

3245-
$formated = '';
3246-
3247-
if($date && $time){
3248-
$formated = gmdate('c',strtotime($date.' '.$time));
3249-
}else{
3250-
if($date){
3251-
$formated = gmdate('c',strtotime($date));
3252-
}
3245+
$formated = '';
3246+
$wp_timezone = wp_timezone();
3247+
3248+
if ( $date ) {
3249+
$datetime = $time ? $date . ' ' . $time : $date;
3250+
$datetime_obj = date_create( $datetime, $wp_timezone );
3251+
if ( $datetime_obj ) {
3252+
$formated = $datetime_obj->format('c');
3253+
}
32533254
}
32543255

32553256
return $formated;
@@ -3480,6 +3481,7 @@ function saswp_get_field_note($pname){
34803481
'ameliabooking' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wpamelia.com/">wpamelia</a>',
34813482
'wpml' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wpml.org">WPML</a>',
34823483
'polylang' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wordpress.org/plugins/polylang/">Polylang</a>',
3484+
'translatepress' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wordpress.org/plugins/translatepress-multilingual/">TranslatePress</a>',
34833485
'autolistings' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wordpress.org/plugins/auto-listings">Auto Listings</a>',
34843486
'wpdiscuz' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://wordpress.org/plugins/wpdiscuz/">Comments – wpDiscuz</a>',
34853487
'rannarecipe' => esc_html__( 'Requires', 'schema-and-structured-data-for-wp' ) .' <a target="_blank" href="https://themeforest.net/item/ranna-food-recipe-wordpress-theme/25157340">Ranna - Food & Recipe</a>',
@@ -5309,29 +5311,31 @@ function saswp_local_file_get_contents($file_path){
53095311

53105312
function saswp_get_seo_press_metadata($type){
53115313

5312-
global $wpdb;
5314+
global $wpdb, $post;
53135315
$meta_value = '';
5314-
$cache_key = 'saswp_seo_press_cache_key_'.$post->ID;
5315-
$result = wp_cache_get( $cache_key );
5316-
if ( false === $result ) {
5317-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Custom table created by seopress plugin
5318-
$result = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}qss WHERE post_id = %d",$post->ID), OBJECT);
5319-
wp_cache_set( $cache_key, $result );
5320-
}
5321-
5322-
if($result){
5323-
$seo_data = unserialize($rows[0]->seo);
5324-
if($type == 'title'){
5325-
if ( isset( $seo_data['title']) && $seo_data['title'] <>''){
5326-
$meta_value = $seo_data['title'];
5327-
}
5316+
if ( is_object( $post ) && isset( $post->ID ) ) {
5317+
$cache_key = 'saswp_seo_press_cache_key_'.$post->ID;
5318+
$result = wp_cache_get( $cache_key );
5319+
if ( false === $result ) {
5320+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Custom table created by seopress plugin
5321+
$result = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}qss WHERE post_id = %d",$post->ID), OBJECT);
5322+
wp_cache_set( $cache_key, $result );
53285323
}
5329-
if($type == 'description'){
5330-
if ( isset( $seo_data['description']) && $seo_data['description'] <>''){
5331-
$meta_value = $seo_data['description'];
5332-
}
5333-
}
5334-
}
5324+
5325+
if($result){
5326+
$seo_data = unserialize($rows[0]->seo);
5327+
if($type == 'title'){
5328+
if ( isset( $seo_data['title']) && $seo_data['title'] <>''){
5329+
$meta_value = $seo_data['title'];
5330+
}
5331+
}
5332+
if($type == 'description'){
5333+
if ( isset( $seo_data['description']) && $seo_data['description'] <>''){
5334+
$meta_value = $seo_data['description'];
5335+
}
5336+
}
5337+
}
5338+
}
53355339
return $meta_value;
53365340
}
53375341

@@ -5353,4 +5357,78 @@ function saswp_delete_uploaded_file( $url ){
53535357
}
53545358
}
53555359

5360+
}
5361+
5362+
/**
5363+
* Function to filter the translatepress content as per the language
5364+
* @param $content string
5365+
* @return $content string
5366+
* @since 1.40
5367+
* */
5368+
add_filter( 'saswp_the_content', 'saswp_filter_translatepress_content' );
5369+
function saswp_filter_translatepress_content( $content ){
5370+
5371+
global $sd_data, $wpdb, $TRP_LANGUAGE;
5372+
5373+
$search = array( '&#8216;', '&#8217;', '&#8220;', '&#8221;', '&#8211;' );
5374+
$replace = array( '\'', '\'', '"', '"', '-' );
5375+
5376+
if ( ! empty( $sd_data['saswp-translatepress'] ) && class_exists( 'TRP_Translate_Press' ) ) {
5377+
5378+
$trp_settings = get_option( 'trp_settings', false );
5379+
$default_language = '';
5380+
if ( isset( $trp_settings['default-language'] ) ) {
5381+
$default_language = $trp_settings['default-language'];
5382+
}
5383+
5384+
if ( ! empty( $TRP_LANGUAGE ) && ! empty( $default_language ) && $TRP_LANGUAGE !== $default_language ) {
5385+
5386+
$trp_meta_table = $wpdb->prefix.'trp_original_meta';
5387+
$post_id = get_the_ID();
5388+
5389+
$meta_table = $wpdb->get_var( "SHOW TABLES LIKE '$trp_meta_table'" );
5390+
5391+
if ( $trp_meta_table == $meta_table ) {
5392+
5393+
$results = $wpdb->get_results( $wpdb->prepare( "SELECT original_id FROM {$trp_meta_table} WHERE meta_value = %d ORDER BY meta_id", $post_id ) );
5394+
5395+
if ( ! empty( $results ) && is_array( $results ) ) {
5396+
5397+
$translate_table = $wpdb->prefix.'trp_dictionary_'.strtolower( $default_language ).'_'.strtolower( $TRP_LANGUAGE );
5398+
$dictinary_table = $wpdb->get_var( "SHOW TABLES LIKE '$translate_table'" );
5399+
5400+
if ( $translate_table == $dictinary_table ) {
5401+
5402+
foreach ( $results as $original ) {
5403+
5404+
if ( is_object( $original ) && ! empty( $original->original_id ) ) {
5405+
5406+
$translated_data = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$translate_table} WHERE original_id = %d", $original->original_id ) );
5407+
5408+
if ( ! empty( $translated_data ) && ! empty( $translated_data->translated ) ) {
5409+
5410+
$original_data = $translated_data->original;
5411+
$original_data = str_replace( $search, $replace, $original_data );
5412+
5413+
$pos = strpos( $content, $original_data );
5414+
5415+
if ( $pos !== false) {
5416+
$content = substr_replace( $content, $translated_data->translated, $pos, strlen( $original_data ) );
5417+
}
5418+
5419+
}
5420+
5421+
}
5422+
}
5423+
}
5424+
5425+
}
5426+
}
5427+
5428+
}
5429+
5430+
}
5431+
5432+
return $content;
5433+
53565434
}

admin_section/js/main-script.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,15 @@ jQuery(document).ready(function($){
13561356
$("#saswp-polylang").val(0);
13571357
}
13581358
break;
1359+
1360+
case 'saswp-translatepress-checkbox':
1361+
saswp_compatibliy_notes(current, id);
1362+
if ($(this).is(':checked')) {
1363+
$("#saswp-translatepress").val(1);
1364+
}else{
1365+
$("#saswp-translatepress").val(0);
1366+
}
1367+
break;
13591368

13601369
case 'saswp-autolistings-checkbox':
13611370
saswp_compatibliy_notes(current, id);

admin_section/js/main-script.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin_section/settings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,19 @@ function saswp_compatibility_page_callback() {
28582858
'id' => 'saswp-polylang',
28592859
'name' => 'sd_data[saswp-polylang]',
28602860
)
2861+
);
2862+
2863+
$translatepress = array(
2864+
'label' => 'TranslatePress',
2865+
'id' => 'saswp-translatepress-checkbox',
2866+
'name' => 'saswp-translatepress-checkbox',
2867+
'type' => 'checkbox',
2868+
'class' => 'checkbox saswp-checkbox',
2869+
'note' => saswp_get_field_note('translatepress'),
2870+
'hidden' => array(
2871+
'id' => 'saswp-translatepress',
2872+
'name' => 'sd_data[saswp-translatepress]',
2873+
)
28612874
);
28622875

28632876
$autolistings = array(
@@ -4585,6 +4598,7 @@ function saswp_compatibility_page_callback() {
45854598
$sabaidiscuss,
45864599
$yoast,
45874600
$polylang,
4601+
$translatepress,
45884602
$autolistings,
45894603
$wpml,
45904604
$metatagmanager,

core/array-list/compatibility-list.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
'opt_name' => 'saswp-polylang',
3030
'part_in' => 'pro',
3131
),
32+
'translatepress' => array(
33+
'name' => 'Translate Press',
34+
'free' => 'translatepress-multilingual/index.php',
35+
'opt_name' => 'saswp-translatepress',
36+
'part_in' => 'free',
37+
),
3238
'wpml' => array(
3339
'name' => 'WPML Multilingual CMS',
3440
'free' => 'sitepress-multilingual-cms/sitepress.php',

core/array-list/schema-properties.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6324,6 +6324,16 @@ function saswp_get_fields_by_schema_type( $schema_id = null, $condition = null,
63246324
'id' => 'saswp_product_additional_type_'.$schema_id,
63256325
'type' => 'text',
63266326
),
6327+
array(
6328+
'label' => 'Product Weight',
6329+
'id' => 'saswp_product_weight_'.$schema_id,
6330+
'type' => 'text',
6331+
),
6332+
array(
6333+
'label' => 'Product Weight Unit',
6334+
'id' => 'saswp_product_weight_unit_'.$schema_id,
6335+
'type' => 'text',
6336+
),
63276337
array(
63286338
'label' => 'Return Policy Applicable Country Code',
63296339
'id' => 'saswp_product_schema_rp_country_code_'.$schema_id,

modules/reviews/class-saswp-reviews-collection.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function saswp_register_collection_post_type() {
223223
'labels' => array(
224224
'name' => esc_html__( 'Collections', 'schema-and-structured-data-for-wp' ),
225225
'add_new' => esc_html__( 'Add Collection', 'schema-and-structured-data-for-wp' ),
226-
'add_new_item' => esc_html__( 'Edit Collection', 'schema-and-structured-data-for-wp' ),
226+
'add_new_item' => esc_html__( 'Add Collection', 'schema-and-structured-data-for-wp' ),
227227
'edit_item' => esc_html__( 'Edit Collection', 'schema-and-structured-data-for-wp' ),
228228
),
229229
'public' => true,
@@ -907,8 +907,12 @@ public function saswp_admin_collection_interface_render() {
907907
<lable><?php echo esc_html__( 'Date Format', 'schema-and-structured-data-for-wp' ); ?></lable>
908908
<select name="saswp_collection_date_format" class="saswp-collection-date-format saswp-coll-settings-options">
909909
<?php
910-
foreach( $date_format as $key => $val){
911-
echo '<option value="'. esc_attr( $key).'" '.($post_meta['saswp_collection_date_format'][0] == $key ? 'selected':'').' >'.esc_html( $val ).'</option>';
910+
foreach( $date_format as $key => $val){
911+
$selected_date = '';
912+
if ( isset( $post_meta['saswp_collection_date_format'][0] ) && $post_meta['saswp_collection_date_format'][0] == $key ) {
913+
$selected_date = 'selected';
914+
}
915+
echo '<option value="'. esc_attr( $key).'" '.esc_attr( $selected_date ).' >'.esc_html( $val ).'</option>';
912916
}
913917
?>
914918
</select>

output/class-saswp-output-compatibility.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,9 @@ public function novelist_on_activation() {
695695
public function polylang_on_activation() {
696696
$this->saswp_update_option_on_compatibility_activation('saswp-polylang');
697697
}
698+
public function translatepress_on_activation() {
699+
$this->saswp_update_option_on_compatibility_activation('saswp-translatepress');
700+
}
698701
public function event_on_on_activation() {
699702
$this->saswp_update_option_on_compatibility_activation('saswp-event-on');
700703
}

output/class-saswp-output-service.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ public function saswp_replace_with_custom_fields_value($input1, $schema_post_id)
31163116
if ( ! empty( $local_offer ) && is_array( $local_offer ) ) {
31173117
$make_offer = array();
31183118
$make_offer['@type'] = 'Offer';
3119-
$make_offer['@id'] = '#service'. $lmo_key + 1;
3119+
$make_offer['@id'] = '#service'. ( $lmo_key + 1 );
31203120
$make_offer['itemOffered'] = $local_offer;
31213121

31223122
$input1['makesOffer'][] = $make_offer;
@@ -5685,6 +5685,11 @@ public function saswp_replace_with_custom_fields_value($input1, $schema_post_id)
56855685
}
56865686
if ( isset( $custom_fields['saswp_product_additional_type']) ) {
56875687
$input1['additionalType'] = $custom_fields['saswp_product_additional_type'];
5688+
}
5689+
if ( ! empty( $custom_fields['saswp_product_weight'] ) && ! empty( $custom_fields['saswp_product_weight_unit'] ) ) {
5690+
$input1['weight']['@type'] = 'QuantitativeValue';
5691+
$input1['weight']['value'] = $custom_fields['saswp_product_weight'];
5692+
$input1['weight']['unitCode'] = $custom_fields['saswp_product_weight_unit'];
56885693
}
56895694
if ( isset( $custom_fields['saswp_product_schema_description']) ) {
56905695
$input1['description'] = wp_strip_all_tags(strip_shortcodes( $custom_fields['saswp_product_schema_description'] ));

output/markup.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,12 @@ function saswp_product_schema_markup($schema_id, $schema_post_id, $all_post_meta
14911491
$input1['additionalType'] = esc_attr( $all_post_meta['saswp_product_additional_type_'.$schema_id][0]);
14921492
}
14931493

1494+
if ( ! empty( $all_post_meta['saswp_product_weight_'.$schema_id][0] ) && ! empty( $all_post_meta['saswp_product_weight_unit_'.$schema_id][0] ) ) {
1495+
$input1['weight']['@type'] = 'QuantitativeValue';
1496+
$input1['weight']['value'] = saswp_remove_warnings( $all_post_meta, 'saswp_product_weight_'.$schema_id, 'saswp_array' );
1497+
$input1['weight']['unitCode'] = saswp_remove_warnings( $all_post_meta, 'saswp_product_weight_unit_'.$schema_id, 'saswp_array' );
1498+
}
1499+
14941500
if(saswp_remove_warnings($all_post_meta, 'saswp_product_schema_enable_rating_'.$schema_id, 'saswp_array') == 1 && saswp_remove_warnings($all_post_meta, 'saswp_product_schema_rating_'.$schema_id, 'saswp_array') && saswp_remove_warnings($all_post_meta, 'saswp_product_schema_review_count_'.$schema_id, 'saswp_array') ) {
14951501

14961502
$input1['aggregateRating'] = array(

0 commit comments

Comments
 (0)