Yoast_Plugin_Conflict_Ajax

Class Yoast_Plugin_Conflict_Ajax.

Defined (1)

The class is defined in the following location(s).

/admin/ajax/class-yoast-plugin-conflict-ajax.php  
  1. class Yoast_Plugin_Conflict_Ajax { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. private $option_name = 'wpseo_dismissed_conflicts'; 
  7.  
  8. /** 
  9. * @var array 
  10. */ 
  11. private $dismissed_conflicts = array(); 
  12.  
  13. /** 
  14. * Initialize the hooks for the AJAX request 
  15. */ 
  16. public function __construct() { 
  17. add_action( 'wp_ajax_wpseo_dismiss_plugin_conflict', array( $this, 'dismiss_notice' ) ); 
  18.  
  19. /** 
  20. * Handles the dismiss notice request 
  21. */ 
  22. public function dismiss_notice() { 
  23. check_ajax_referer( 'dismiss-plugin-conflict' ); 
  24.  
  25. $conflict_data = filter_input( INPUT_POST, 'data', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); 
  26.  
  27. $this->dismissed_conflicts = $this->get_dismissed_conflicts( $conflict_data['section'] ); 
  28.  
  29. $this->compare_plugins( $conflict_data['plugins'] ); 
  30.  
  31. $this->save_dismissed_conflicts( $conflict_data['section'] ); 
  32.  
  33. wp_die( 'true' ); 
  34.  
  35. /** 
  36. * Getting the user option from the database 
  37. * @return bool|array 
  38. */ 
  39. private function get_dismissed_option() { 
  40. return get_user_meta( get_current_user_id(), $this->option_name, true ); 
  41.  
  42. /** 
  43. * Getting the dismissed conflicts from the database 
  44. * @param string $plugin_section Type of conflict group (such as Open Graph or sitemap). 
  45. * @return array 
  46. */ 
  47. private function get_dismissed_conflicts( $plugin_section ) { 
  48. $dismissed_conflicts = $this->get_dismissed_option(); 
  49.  
  50. if ( is_array( $dismissed_conflicts ) && array_key_exists( $plugin_section, $dismissed_conflicts ) ) { 
  51. return $dismissed_conflicts[ $plugin_section ]; 
  52.  
  53. return array(); 
  54.  
  55. /** 
  56. * Storing the conflicting plugins as an user option in the database 
  57. * @param string $plugin_section Plugin conflict type (such as Open Graph or sitemap). 
  58. */ 
  59. private function save_dismissed_conflicts( $plugin_section ) { 
  60. $dismissed_conflicts = $this->get_dismissed_option(); 
  61.  
  62. $dismissed_conflicts[ $plugin_section ] = $this->dismissed_conflicts; 
  63.  
  64. update_user_meta( get_current_user_id(), $this->option_name, $dismissed_conflicts ); 
  65.  
  66. /** 
  67. * Loop through the plugins to compare them with the already stored dismissed plugin conflicts 
  68. * @param array $posted_plugins Plugin set to check. 
  69. */ 
  70. public function compare_plugins( array $posted_plugins ) { 
  71. foreach ( $posted_plugins as $posted_plugin ) { 
  72. $this->compare_plugin( $posted_plugin ); 
  73.  
  74. /** 
  75. * Check if plugin is already dismissed, if not store it in the array that will be saved later 
  76. * @param string $posted_plugin Plugin to check against dismissed conflicts. 
  77. */ 
  78. private function compare_plugin( $posted_plugin ) { 
  79. if ( ! in_array( $posted_plugin, $this->dismissed_conflicts ) ) { 
  80. $this->dismissed_conflicts[] = $posted_plugin;