Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/php/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ public function load_plugin() {
new Upgrader( PLUGIN_VERSION, $this->db );
new Admin_Bar();

if ( is_admin() ) {
new Promotion_Manager();
}

$this->init_snippet_files();

add_action( 'rest_api_init', [ $this, 'init_rest_api' ], 1 );
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/Plugin_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Code_Snippets;

use Code_Snippets\Integration\Promotions\Other\Elementor_Editor;

/**
* Tests for the main plugin class.
*/
class Plugin_Test extends UnitTestCase {

/**
* Loading the plugin in the admin registers one Elementor promotion callback.
*
* @return void
*/
public function test_load_plugin_registers_elementor_promotion_once(): void {
set_current_screen( 'dashboard' );
Comment thread
coderabbitai[bot] marked this conversation as resolved.

$callbacks_before = $this->get_elementor_promotion_callbacks();

$plugin = new Plugin();
$plugin->load_plugin();

$this->assertCount( count( $callbacks_before ) + 1, $this->get_elementor_promotion_callbacks() );
}

/**
* Retrieve the callbacks that initialize Elementor promotions.
*
* @return array
*/
private function get_elementor_promotion_callbacks(): array {
global $wp_filter;

$promotion_callbacks = [];

foreach ( $wp_filter['elementor/init']->callbacks ?? [] as $callbacks ) {
foreach ( $callbacks as $callback ) {
$function = $callback['function'];

if ( is_array( $function ) && $function[0] instanceof Elementor_Editor && 'promotion_in_custom_css_section' === $function[1] ) {
$promotion_callbacks[] = $function;
}
}
}

return $promotion_callbacks;
}
}
Loading