Filter uncanny-toolkit-pro

active_plugins

Filters the list of currently active plugins before they are loaded by WordPress.

add_filter( 'active_plugins', $callback, 10, 1 );

Description

This filter hook allows modification of the list of currently active plugins before it's retrieved. Developers can use this to programmatically enable or disable plugins for specific contexts or to simulate a different plugin state for testing purposes. The hook receives the result of `get_option('active_plugins')`.


Usage

add_filter( 'active_plugins', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

add_filter( 'active_plugins', 'my_custom_active_plugins_filter', 10, 1 );

/**
 * Example filter for the 'active_plugins' hook.
 *
 * This function demonstrates how to conditionally modify the list of active plugins.
 * In this specific example, it checks if a plugin named 'my-special-plugin/my-special-plugin.php'
 * is active. If it is, it logs a message. This is a simplified demonstration;
 * real-world use cases might involve disabling certain plugins based on conditions,
 * or altering plugin behavior by modifying their activation status.
 *
 * @param array $active_plugins An array of paths to the active plugins.
 * @return array The potentially modified array of active plugins.
 */
function my_custom_active_plugins_filter( $active_plugins ) {
	// Check if 'my-special-plugin/my-special-plugin.php' is in the list of active plugins.
	if ( in_array( 'my-special-plugin/my-special-plugin.php', $active_plugins ) ) {
		// Log a message if the special plugin is active.
		error_log( 'My special plugin is active!' );

		// Example of conditionally removing a plugin (use with extreme caution in production).
		// $key = array_search( 'another-plugin-to-disable/another-plugin-to-disable.php', $active_plugins );
		// if ( $key !== false ) {
		//     unset( $active_plugins[ $key ] );
		// }
	}

	// Always return the array, even if modified.
	return $active_plugins;
}

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/clone-posts-pages-learn-dash-contents.php:197
src/classes/clone-posts-pages-learn-dash-contents.php:249

public static function uncanny_clone_post_publish_box() {
		if ( ! filter_has_var( INPUT_GET, 'post' ) ) {
			return;
		}

		$post = get_post( absint( filter_input( INPUT_GET, 'post' ) ) );
		if ( 'sfwd-assignment' === $post->post_type || ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) && 'product' === $post->post_type ) ) {
			return;
		}

		?>
		<div class="misc-pub-section misc-pub-clone" id="Clone">
			<?php
			if ( 'sfwd-quiz' === $post->post_type ) {
				$action = '?action=clone_learndash_quiz_contents&return_to_post=true&post=' . $post->ID . '&wpnonce=' . wp_create_nonce( __CLASS__ );
			} else {
				$action = '?action=clone_post_contents&return_to_post=true&post=' . $post->ID . '&wpnonce=' . wp_create_nonce( __CLASS__ );
			}
			$post_type_object = get_post_type_object( $post->post_type );

			?>
			<style>
				.misc-pub-clone #post-clone-display::before {
					content: "f105";
					font: 400 20px/1 dashicons;
					speak: none;
					display: inline-block;
					padding: 0 2px 0 0;
					top: 0;
					left: -1px;
					position: relative;
					vertical-align: top;
					-webkit-font-smoothing: antialiased;
					-moz-osx-font-smoothing: grayscale;
					text-decoration: none !important;
					color: #82878c;
				}
			</style>
			<span id="post-clone-display"><strong>Action:</strong> </span>
			<a href="<?php echo $action; ?>" class="edit-visibility hide-if-no-js"><span
					aria-hidden="true">Clone this <?php echo $post_type_object->labels->singular_name; ?></span></a>
		</div>
		<?php
	}

Scroll to Top