PluginProbe
Faust.js / 1.0.2
Faust.js v1.0.2
1.8.12 1.8.11 1.4.1 1.8.0 1.8.8 1.8.9 trunk 0.7.0 0.7.1 0.7.10 0.7.11 0.7.3 0.7.4 0.7.5 0.7.6 0.7.7 0.7.8 0.7.9 0.8.0 0.8.1 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 All 40 releases
faustwp / includes / detect-conflicts / functions.php

functions.php in Faust.js 1.0.2, at includes/detect-conflicts/functions.php

122 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions for detecting and reporting plugin conflicts.
4 *
5 * @package FaustWP
6 */
7
8 namespace WPE\FaustWP\Detect_Conflicts;
9
10 /** User meta key for storing list of dismissed plugin conflicts. */
11 const DISMISSED_CONFLICTS_META_KEY = 'faustwp_conflicts_dismissed';
12
13 /**
14 * Get the full list of plugins known to conflict with FaustWP.
15 *
16 * The list is an array of plugin file paths relative to the plugins directory.
17 *
18 * @return array List of plugins.
19 */
20 function get_plugin_conflict_list() {
21 return array(
22 'elementor/elementor.php',
23 );
24 }
25
26 /**
27 * Get the active plugins known to conflict with FaustWP.
28 *
29 * @see WPE\FaustWP\Detect_Conflicts\get_plugin_conflict_list()
30 *
31 * @param array|null $conflict_list Optional. Alternative list of plugins known to conflict.
32 * @param boolean $include_dismissed Whether to include dismissed conflicts. Default false.
33 * @return array List of active conflicting plugins.
34 */
35 function get_plugin_conflicts( $conflict_list = null, $include_dismissed = false ) {
36 $plugins = is_array( $conflict_list ) ? $conflict_list : get_plugin_conflict_list();
37
38 foreach ( $plugins as $index => $plugin ) {
39 if (
40 ! is_plugin_active( $plugin ) ||
41 ( ! $include_dismissed && is_conflict_dismissed( $plugin ) )
42 ) {
43 unset( $plugins[ $index ] );
44 }
45 }
46
47 return $plugins;
48 }
49
50 /**
51 * Determines whether the plugin conflicts warning should be shown.
52 *
53 * The warning is only shown on the plugins page and Faust settings page
54 * when the user has the activate_plugins capability and there are active
55 * conflicts.
56 *
57 * @return boolean True if the warning should be shown.
58 */
59 function needs_warning() {
60 if ( ! current_user_can( 'activate_plugins' ) ) {
61 return false;
62 }
63
64 $screens_to_show = array( 'plugins', 'settings_page_faustwp-settings' );
65 $current_screen = get_current_screen();
66 if ( is_object( $current_screen ) && ! in_array( $current_screen->id, $screens_to_show, true ) ) {
67 return false;
68 }
69
70 $plugins = get_plugin_conflicts();
71
72 return ! empty( $plugins );
73 }
74
75 /**
76 * Get the list of dismissed plugin conflicts for the current user.
77 *
78 * @return array The list of dismissed plugin conflicts.
79 */
80 function get_conflicts_dismissed() {
81 $dismissed = get_user_meta( get_current_user_id(), DISMISSED_CONFLICTS_META_KEY, true );
82 return $dismissed ? $dismissed : array();
83 }
84
85 /**
86 * Clears the list of dismissed plugin conflicts for the current user.
87 *
88 * @return boolean True on success, false on failure.
89 */
90 function delete_conflicts_dismissed() {
91 return delete_user_meta( get_current_user_id(), DISMISSED_CONFLICTS_META_KEY );
92 }
93
94 /**
95 * Checks whether a plugin conflict has been dismissed by the current user.
96 *
97 * @param string $plugin Path to the plugin file relative to the plugins directory.
98 * @return boolean True if the plugin conflict has been dismissed.
99 */
100 function is_conflict_dismissed( $plugin ) {
101 $dismissed = get_conflicts_dismissed();
102 return in_array( $plugin, $dismissed, true );
103 }
104
105 /**
106 * Adds any plugins that are currently active, in the conflict list, and not yet
107 * dismissed to the current user's list of dismissed plugin conflicts.
108 *
109 * @param array $conflict_list Optional. Alternative list of plugins known to conflict.
110 * @return void
111 */
112 function dismiss_active_conflicts( $conflict_list = null ) {
113 $plugins = get_plugin_conflicts( $conflict_list ); // Excludes dismissed conflicts.
114 $dismissed = get_conflicts_dismissed();
115
116 foreach ( $plugins as $plugin ) {
117 $dismissed[] = $plugin;
118 }
119
120 update_user_meta( get_current_user_id(), DISMISSED_CONFLICTS_META_KEY, $dismissed );
121 }
122