/wp-content/plugins/polylang/modules/share-slug/settings-share-slug.php

https://bitbucket.org/gordievsky/aquatech · PHP · 81 lines · 39 code · 8 blank · 34 comment · 6 complexity · 7e9ab3b008253e0b83db2962e98e0484 MD5 · raw file

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