| @@ -1903,8 +1903,78 @@ | ||
| 1903 | 1903 | return $data; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | 1906 | /** |
| 1907 | + * Store recently activated Give's addons to wp options. | |
| 1908 | + * | |
| 1909 | + * @since 4.16.7.1 Moved from includes/admin/plugins.php so the listener is registered on every | |
| 1910 | + * request, and fall back to the plugin file passed by the `activated_plugin` | |
| 1911 | + * action so add-ons activated outside of plugins.php (REST, WP-CLI, | |
| 1912 | + * programmatic `activate_plugin()`, etc.) are recorded too. | |
| 1913 | + * @since 2.1.0 | |
| 1914 | + * | |
| 1915 | + * @param string $activated_plugin Plugin file passed by the `activated_plugin` action. | |
| 1916 | + */ | |
| 1917 | +function give_recently_activated_addons( $activated_plugin = '' ) { | |
| 1918 | + $plugins = []; | |
| 1919 | + | |
| 1920 | + // Check if action is set. | |
| 1921 | + if ( isset( $_REQUEST['action'] ) ) { | |
| 1922 | + $plugin_action = ( '-1' !== $_REQUEST['action'] ) ? $_REQUEST['action'] : ( isset( $_REQUEST['action2'] ) ? $_REQUEST['action2'] : '' ); | |
| 1923 | + | |
| 1924 | + switch ( $plugin_action ) { | |
| 1925 | + case 'activate': // Single add-on activation. | |
| 1926 | + $plugins[] = $_REQUEST['plugin']; | |
| 1927 | + break; | |
| 1928 | + case 'activate-selected': // If multiple add-ons activated. | |
| 1929 | + $plugins = $_REQUEST['checked']; | |
| 1930 | + break; | |
| 1931 | + } | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + /** | |
| 1935 | + * Activations that do not come from the plugins.php form (Harbor's feature manager, | |
| 1936 | + * WP-CLI, plugin dependencies, any direct `activate_plugin()` call) have no matching | |
| 1937 | + * request parameters, so use the plugin file the action itself provides. | |
| 1938 | + */ | |
| 1939 | + if ( empty( $plugins ) && ! empty( $activated_plugin ) ) { | |
| 1940 | + $plugins[] = $activated_plugin; | |
| 1941 | + } | |
| 1942 | + | |
| 1943 | + if ( ! empty( $plugins ) ) { | |
| 1944 | + | |
| 1945 | + $give_addons = give_get_recently_activated_addons(); | |
| 1946 | + | |
| 1947 | + foreach ( $plugins as $plugin ) { | |
| 1948 | + // Get plugins which has 'Give-' as prefix. | |
| 1949 | + if ( stripos( $plugin, 'Give-' ) !== false ) { | |
| 1950 | + $give_addons[] = $plugin; | |
| 1951 | + } | |
| 1952 | + } | |
| 1953 | + | |
| 1954 | + if ( ! empty( $give_addons ) ) { | |
| 1955 | + // Update the Give's activated add-ons. | |
| 1956 | + update_option( 'give_recently_activated_addons', $give_addons, false ); | |
| 1957 | + } | |
| 1958 | + } | |
| 1959 | +} | |
| 1960 | + | |
| 1961 | +// Add add-on plugins to wp option table. | |
| 1962 | +add_action( 'activated_plugin', 'give_recently_activated_addons', 10 ); | |
| 1963 | + | |
| 1964 | +/** | |
| 1965 | + * Get list of add-on last activated. | |
| 1966 | + * | |
| 1967 | + * @since 4.16.7.1 Moved from includes/admin/plugins.php. | |
| 1968 | + * @since 2.1.3 | |
| 1969 | + * | |
| 1970 | + * @return mixed|array list of recently activated add-on | |
| 1971 | + */ | |
| 1972 | +function give_get_recently_activated_addons() { | |
| 1973 | + return get_option( 'give_recently_activated_addons', [] ); | |
| 1974 | +} | |
| 1975 | + | |
| 1976 | +/** | |
| 1907 | 1977 | * Get time interval for which nonce is valid |
| 1908 | 1978 | * |
| 1909 | 1979 | * @return int |
| 1910 | 1980 | * @since 2.1.3 |