first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class WPML_Post_Slug_Translation_Records extends WPML_Slug_Translation_Records {
|
||||
|
||||
const STRING_NAME = 'URL slug: %s';
|
||||
|
||||
/**
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_string_name( $slug ) {
|
||||
return sprintf( self::STRING_NAME, $slug );
|
||||
}
|
||||
|
||||
/** @return string */
|
||||
protected function get_element_type() {
|
||||
return 'post';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @todo: Move these settings to an independent option
|
||||
* like WPML_ST_Tax_Slug_Translation_Settings::OPTION_NAME
|
||||
*/
|
||||
class WPML_ST_Post_Slug_Translation_Settings extends WPML_ST_Slug_Translation_Settings {
|
||||
|
||||
const KEY_IN_SITEPRESS_SETTINGS = 'posts_slug_translation';
|
||||
|
||||
/** @var SitePress $sitepress */
|
||||
private $sitepress;
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct( SitePress $sitepress ) {
|
||||
$this->sitepress = $sitepress;
|
||||
$this->settings = $sitepress->get_setting( self::KEY_IN_SITEPRESS_SETTINGS, array( ) );
|
||||
}
|
||||
|
||||
/** @param bool $enabled */
|
||||
public function set_enabled( $enabled ) {
|
||||
parent::set_enabled( $enabled );
|
||||
|
||||
/**
|
||||
* Backward compatibility with 3rd part plugins
|
||||
* The `on` key has been replaced by an independent option
|
||||
* WPML_ST_Slug_Translation_Settings::KEY_ENABLED_GLOBALLY
|
||||
*/
|
||||
$this->settings['on'] = (int) $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_translated( $type ) {
|
||||
return ! empty( $this->settings['types'][ $type ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param bool $is_enabled
|
||||
*/
|
||||
public function set_type( $type, $is_enabled ) {
|
||||
if ( $is_enabled ) {
|
||||
$this->settings['types'][ $type ] = 1;
|
||||
} else {
|
||||
unset( $this->settings['types'][ $type ] );
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
$this->sitepress->set_setting( self::KEY_IN_SITEPRESS_SETTINGS, $this->settings, true );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user