| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Settings class to advertize the Share slugs module |
| 5 |
* |
| 6 |
* @since 1.9 |
| 7 |
*/ |
| 8 |
class PLL_Settings_Share_Slug extends PLL_Settings_Module { |
| 9 |
|
| 10 |
/** |
| 11 |
* Constructor |
| 12 |
* |
| 13 |
* @since 1.9 |
| 14 |
* |
| 15 |
* @param object $polylang polylang object |
| 16 |
*/ |
| 17 |
public function __construct( &$polylang ) { |
| 18 |
parent::__construct( |
| 19 |
$polylang, |
| 20 |
array( |
| 21 |
'module' => 'share-slugs', |
| 22 |
'title' => __( 'Share slugs', 'polylang' ), |
| 23 |
'description' => __( 'Allows to share the same url slug across languages for posts and terms.', 'polylang' ), |
| 24 |
) |
| 25 |
); |
| 26 |
|
| 27 |
if ( class_exists( 'PLL_Share_Post_Slug', true ) && get_option( 'permalink_structure' ) ) { |
| 28 |
add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) ); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Tells if the module is active |
| 34 |
* |
| 35 |
* @since 1.9 |
| 36 |
* |
| 37 |
* @return bool |
| 38 |
*/ |
| 39 |
public function is_active() { |
| 40 |
return class_exists( 'PLL_Share_Post_Slug', true ) && $this->options['force_lang'] && get_option( 'permalink_structure' ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Displays upgrade message |
| 45 |
* |
| 46 |
* @since 1.9 |
| 47 |
* |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
public function get_upgrade_message() { |
| 51 |
return class_exists( 'PLL_Share_Post_Slug', true ) ? '' : $this->default_upgrade_message(); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Displays the javascript to handle dynamically the change in url modifications |
| 56 |
* as sharing slugs is not possible when the language is set from the content |
| 57 |
* |
| 58 |
* @since 1.9 |
| 59 |
*/ |
| 60 |
public function print_js() { |
| 61 |
wp_enqueue_script( 'jquery' ); |
| 62 |
|
| 63 |
$activated = sprintf( '<span class="activated">%s</span>', $this->action_links['activated'] ); |
| 64 |
$deactivated = sprintf( '<span class="deactivated">%s</span>', $this->action_links['deactivated'] ); |
| 65 |
|
| 66 |
?> |
| 67 |
<script type='text/javascript'> |
| 68 |
//<![CDATA[ |
| 69 |
( function( $ ){ |
| 70 |
$( "input[name='force_lang']" ).change( function() { |
| 71 |
var value = $( this ).val(); |
| 72 |
if ( value > 0 ) { |
| 73 |
$( "#pll-module-share-slugs" ).removeClass( "inactive" ).addClass( "active" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $activated; ?>' ); |
| 74 |
} |
| 75 |
else { |
| 76 |
$( "#pll-module-share-slugs" ).removeClass( "active" ).addClass( "inactive" ).children( "td" ).children( ".row-actions" ).html( '<?php echo $deactivated; ?>' ); |
| 77 |
} |
| 78 |
} ); |
| 79 |
} )( jQuery ); |
| 80 |
// ]]> |
| 81 |
</script> |
| 82 |
<?php |
| 83 |
} |
| 84 |
} |
| 85 |
|