WPML compatibility tweaks
This commit is contained in:
66
includes/class-sp-wpml.php
Normal file
66
includes/class-sp-wpml.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* WPML Class
|
||||
*
|
||||
* The SportsPress WPML class handles all WPML-related localization hooks.
|
||||
*
|
||||
* @class SP_WPML
|
||||
* @version 1.1.9
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
if ( ! class_exists( 'SP_WPML' ) ) :
|
||||
|
||||
/**
|
||||
* SP_WPML Class
|
||||
*/
|
||||
class SP_WPML {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'the_title', array( $this, 'the_title' ), 5, 2 );
|
||||
add_filter( 'post_type_link', array( $this, 'post_type_link' ), 5, 2 );
|
||||
}
|
||||
|
||||
public static function the_title( $title, $id = null ) {
|
||||
if ( self::can_localize( $id, get_post_type( $id ) ) ):
|
||||
// Get translated post ID
|
||||
$translated_id = icl_object_id( $id, 'any', false, ICL_LANGUAGE_CODE );
|
||||
|
||||
if ( $translated_id ):
|
||||
$post = get_post( $translated_id );
|
||||
$title = $post->post_title;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
public static function post_type_link( $url, $post ) {
|
||||
if ( self::can_localize( $post->ID, $post->post_type ) ):
|
||||
// Get translated post ID
|
||||
$translated_id = icl_object_id( $post->ID, 'any', false, ICL_LANGUAGE_CODE );
|
||||
|
||||
if ( $translated_id ):
|
||||
$url .= '?lang=ja';
|
||||
//$url = get_permalink( $translated_id );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function can_localize( $id, $post_type ) {
|
||||
return ( function_exists( 'icl_object_id' ) && is_sp_post_type( $post_type ) && $id != get_the_ID() );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
return new SP_WPML();
|
||||
@@ -105,7 +105,9 @@ add_filter( 'previous_post_link', 'sportspress_hide_adjacent_post_links', 10, 4
|
||||
add_filter( 'next_post_link', 'sportspress_hide_adjacent_post_links', 10, 4 );
|
||||
|
||||
function sportspress_the_title( $title, $id = null ) {
|
||||
if ( $id && ! is_admin() && ! current_theme_supports( 'sportspress' ) && in_the_loop() && $id == get_the_ID() ):
|
||||
if ( ! $id ) return $title;
|
||||
|
||||
if ( ! is_admin() && ! current_theme_supports( 'sportspress' ) && in_the_loop() && $id == get_the_ID() ):
|
||||
if ( is_singular( 'sp_player' ) ):
|
||||
$number = get_post_meta( $id, 'sp_number', true );
|
||||
if ( $number != null ):
|
||||
@@ -131,11 +133,12 @@ function sportspress_the_title( $title, $id = null ) {
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
return $title;
|
||||
}
|
||||
add_filter( 'the_title', 'sportspress_the_title', 10, 2 );
|
||||
|
||||
function sportspress_gettext( $translated_text, $untranslated_text, $domain ) {
|
||||
function sportspress_gettext( $translated_text, $untranslated_text, $domain = null ) {
|
||||
global $typenow;
|
||||
|
||||
if ( is_admin() ):
|
||||
|
||||
@@ -220,6 +220,9 @@ final class SportsPress {
|
||||
|
||||
// Include template hooks in time for themes to remove/modify them
|
||||
include_once( 'includes/sp-template-hooks.php' );
|
||||
|
||||
// WPML-related localization hooks
|
||||
include_once( 'includes/class-sp-wpml.php' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user