Completed
Push — develop ( d70d7b...75b5a2 )
by
unknown
05:21 queued 02:38
created

Wordlift_Tinymce_Adapter::mce_external_plugins()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 1
dl 0
loc 44
rs 8.5937
c 0
b 0
f 0
1
<?php
2
/**
3
 * Adapters: TinyMCE Editor Adapter.
4
 *
5
 * @since   3.12.0
6
 * @package Wordlift
7
 */
8
9
/**
10
 * Define the {@link Wordlift_Tinymce_Adapter} class.
11
 *
12
 * @since   3.12.0
13
 * @package Wordlift
14
 */
15
class Wordlift_Tinymce_Adapter {
16
17
	/**
18
	 * The {@link Wordlift} plugin instance.
19
	 *
20
	 * @since  3.12.0
21
	 * @access private
22
	 * @var \Wordlift $plugin The {@link Wordlift} plugin instance.
23
	 */
24
	private $plugin;
25
26
	/**
27
	 * Wordlift_Tinymce_Adapter constructor.
28
	 *
29
	 * @param \Wordlift $plugin The {@link Wordlift} plugin instance.
30
	 */
31
	public function __construct( $plugin ) {
32
33
		$this->plugin = $plugin;
34
35
	}
36
37
	/**
38
	 * Load the TinyMCE plugin. This method is called by the WP mce_external_plugins hook.
39
	 *
40
	 * @param array $plugins The existing plugins array.
41
	 *
42
	 * @return array The modified plugins array.
43
	 * @since 3.12.0
44
	 */
45
	function mce_external_plugins( $plugins ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
47
		/**
48
		 * Bail out if you are on Media Library
49
		 *
50
		 * @since 3.27.1
51
		 *
52
		 * @see https://github.com/insideout10/wordlift-plugin/issues/1122
53
		 */
54
		if ( get_current_screen()->base === 'upload' ) {
55
			return $plugins;
56
		}
57
58
		/*
59
		 * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box.
60
		 *
61
		 * @since 3.20.3
62
		 *
63
		 * @see https://github.com/insideout10/wordlift-plugin/issues/914
64
		 */
65
		if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) {
66
			return $plugins;
67
		}
68
69
		// Get WordLift's version as a cache killer.
70
		$version = $this->plugin->get_version();
71
72
		// User can edit?
73
		$can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
74
75
		// If user can't edit or rich editing isn't enabled, bail out.
76
		if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) {
77
			return $plugins;
78
		}
79
80
		// Add our own JavaScript file to TinyMCE's extensions.
81
		// DO NOT use the minified version, it'll yield errors with AngularJS.
82
		$plugins['wordlift']      = plugin_dir_url( dirname( __FILE__ ) ) . 'js/wordlift-reloaded.js?ver=' . $version;
83
		$plugins['wl_shortcodes'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift_shortcode_tinymce_plugin.js?ver=' . $version;
84
		$plugins['wl_tinymce']    = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/tinymce.js?ver=' . $version;
85
		$plugins['wl_tinymce_2']  = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/tiny-mce.js?ver=' . $version;
86
87
		return $plugins;
88
	}
89
90
}
91