/lib/filters.php

  1. <?php 
  2. /** 
  3. * License: GPLv3 
  4. * License URI: https://www.gnu.org/licenses/gpl.txt 
  5. * Copyright 2012-2017 Jean-Sebastien Morisset (https://surniaulula.com/) 
  6. */ 
  7.  
  8. if ( ! defined( 'ABSPATH' ) ) { 
  9. die( 'These aren\'t the droids you\'re looking for...' ); 
  10.  
  11. if ( ! class_exists( 'NgfbFilters' ) ) { 
  12.  
  13. class NgfbFilters { 
  14.  
  15. private $p; 
  16.  
  17. public function __construct( &$plugin ) { 
  18. $this->p =& $plugin; 
  19. if ( $this->p->debug->enabled ) 
  20. $this->p->debug->mark(); 
  21.  
  22. if ( is_admin() ) { 
  23. // cleanup incorrect Yoast SEO notifications 
  24. if ( function_exists( 'wpseo_init' ) ) { // includes wpseo premium 
  25. add_action( 'admin_init', array( &$this, 'cleanup_wpseo_notifications' ), 15 ); 
  26.  
  27. if ( class_exists( 'GFForms' ) ) { 
  28. add_action( 'gform_noconflict_styles', array( $this, 'update_noconflict_styles' ) ); 
  29. add_action( 'gform_noconflict_scripts', array( $this, 'update_noconflict_scripts' ) ); 
  30.  
  31. if ( class_exists( 'GravityView_Plugin' ) ) { 
  32. add_action( 'gravityview_noconflict_styles', array( $this, 'update_noconflict_styles' ) ); 
  33. add_action( 'gravityview_noconflict_scripts', array( $this, 'update_noconflict_scripts' ) ); 
  34.  
  35. } else { 
  36. // disable jetPack open graph meta tags 
  37. if ( SucomUtil::active_plugins( 'jetpack/jetpack.php' ) ) { 
  38. add_filter( 'jetpack_enable_opengraph', '__return_false', 1000 ); 
  39. add_filter( 'jetpack_enable_open_graph', '__return_false', 1000 ); 
  40. add_filter( 'jetpack_disable_twitter_cards', '__return_true', 1000 ); 
  41.  
  42. // disable Yoast SEO social meta tags 
  43. // execute after add_action( 'template_redirect', 'wpseo_frontend_head_init', 999 ); 
  44. if ( function_exists( 'wpseo_init' ) ) { // includes wpseo premium 
  45. add_action( 'template_redirect', array( &$this, 'cleanup_wpseo_filters' ), 9000 ); 
  46.  
  47. // honor the FORCE_SSL constant on the front-end with a 301 redirect 
  48. if ( ! empty( $this->p->options['plugin_honor_force_ssl'] ) ) { 
  49. if ( SucomUtil::get_const( 'FORCE_SSL' ) ) { 
  50. add_action( 'wp_loaded', array( __CLASS__, 'force_ssl_redirect' ), -1000 ); 
  51.  
  52. public function update_noconflict_styles( $styles ) { 
  53. return array_merge( $styles, array( 
  54. 'jquery-ui.js',  
  55. 'jquery-qtip.js',  
  56. 'sucom-admin-page',  
  57. 'sucom-settings-table',  
  58. 'sucom-metabox-tabs',  
  59. 'wp-color-picker',  
  60. ) ); 
  61.  
  62. public function update_noconflict_scripts( $scripts ) { 
  63. return array_merge( $scripts, array( 
  64. 'jquery-ui-datepicker',  
  65. 'jquery-qtip',  
  66. 'sucom-metabox',  
  67. 'sucom-tooltips',  
  68. 'wp-color-picker',  
  69. 'sucom-admin-media',  
  70. ) ); 
  71.  
  72. /** 
  73. * Cleanup incorrect Yoast SEO notifications. 
  74. */ 
  75. public function cleanup_wpseo_notifications() { 
  76. if ( $this->p->debug->enabled ) 
  77. $this->p->debug->mark(); 
  78.  
  79. if ( class_exists( 'Yoast_Notification_Center' ) ) { 
  80. $lca = $this->p->cf['lca']; 
  81. $info = $this->p->cf['plugin'][$lca]; 
  82. $name = $this->p->cf['plugin'][$lca]['name']; 
  83.  
  84. // wordpress SEO v4 
  85. if ( method_exists( 'Yoast_Notification_Center', 'get_notification_by_id' ) ) { 
  86. $id = 'wpseo-conflict-'.md5( $info['base'] ); 
  87. $msg = '<style>#'.$id.'{display:none;}</style>'; 
  88. $notif_center = Yoast_Notification_Center::get(); 
  89.  
  90. if ( ( $notif_obj = $notif_center->get_notification_by_id( $id ) ) && $notif_obj->message !== $msg ) { 
  91. update_user_meta( get_current_user_id(), $notif_obj->get_dismissal_key(), 'seen' ); 
  92. $notif_obj = new Yoast_Notification( $msg, array( 'id' => $id ) ); 
  93. $notif_center->add_notification( $notif_obj ); 
  94. } elseif ( defined( 'Yoast_Notification_Center::TRANSIENT_KEY' ) ) { 
  95. if ( ( $wpseo_notif = get_transient( Yoast_Notification_Center::TRANSIENT_KEY ) ) !== false ) { 
  96. $wpseo_notif = json_decode( $wpseo_notif ); 
  97. if ( ! empty( $wpseo_notif ) ) { 
  98. foreach ( $wpseo_notif as $num => $msgs ) { 
  99. if ( isset( $msgs->options->type ) && $msgs->options->type == 'error' ) { 
  100. if ( strpos( $msgs->message, $name ) !== false ) { 
  101. unset( $wpseo_notif[$num] ); 
  102. set_transient( Yoast_Notification_Center::TRANSIENT_KEY,  
  103. json_encode( $wpseo_notif ) ); 
  104.  
  105. /** 
  106. * Disable Yoast SEO social meta tags. 
  107. */ 
  108. public function cleanup_wpseo_filters() { 
  109.  
  110. if ( $this->p->debug->enabled ) { 
  111. $this->p->debug->mark(); 
  112.  
  113. if ( isset( $GLOBALS['wpseo_og'] ) && is_object( $GLOBALS['wpseo_og'] ) &&  
  114. ( $prio = has_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ) ) ) !== false ) { 
  115. if ( $this->p->debug->enabled ) { 
  116. $this->p->debug->log( 'removing wpseo_head action for opengraph' ); 
  117. $ret = remove_action( 'wpseo_head', array( $GLOBALS['wpseo_og'], 'opengraph' ), $prio ); 
  118.  
  119. if ( class_exists( 'WPSEO_Twitter' ) && 
  120. ( $prio = has_action( 'wpseo_head', array( 'WPSEO_Twitter', 'get_instance' ) ) ) !== false ) { 
  121. if ( $this->p->debug->enabled ) { 
  122. $this->p->debug->log( 'removing wpseo_head action for twitter' ); 
  123. $ret = remove_action( 'wpseo_head', array( 'WPSEO_Twitter', 'get_instance' ), $prio ); 
  124.  
  125. if ( isset( WPSEO_Frontend::$instance ) && 
  126. ( $prio = has_action( 'wpseo_head', array( WPSEO_Frontend::$instance, 'publisher' ) ) ) !== false ) { 
  127. if ( $this->p->debug->enabled ) { 
  128. $this->p->debug->log( 'removing wpseo_head action for publisher' ); 
  129. $ret = remove_action( 'wpseo_head', array( WPSEO_Frontend::$instance, 'publisher' ), $prio ); 
  130.  
  131. if ( $this->p->debug->enabled ) { 
  132. $this->p->debug->log( 'disabling wpseo_json_ld_output filter' ); 
  133. add_filter( 'wpseo_json_ld_output', '__return_empty_array', 9000 ); 
  134.  
  135. /** 
  136. * Redirect from HTTP to HTTPS if the current webpage URL is 
  137. * not HTTPS. A 301 redirect is considered a best practice when 
  138. * moving from HTTP to HTTPS. See 
  139. * https://en.wikipedia.org/wiki/HTTP_301 for more info. 
  140. */ 
  141. public static function force_ssl_redirect() { 
  142. // check for web server variables in case WP is being used from the command line 
  143. if ( isset( $_SERVER['HTTP_HOST'] ) && isset( $_SERVER['REQUEST_URI'] ) ) { 
  144. if ( ! SucomUtil::is_https() ) { 
  145. wp_redirect( 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], 301 ); 
  146. exit(); 
  147.  
  148. ?> 
.