Completed
Push — develop ( 558e95...0accb6 )
by David
04:03
created

Wordlift_Tinymce_Adapter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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
	 * @since 3.12.0
41
	 *
42
	 * @param array $plugins The existing plugins array.
43
	 *
44
	 * @return array The modified plugins array.
45
	 */
46
	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...
47
48
		// Get WordLift's version as a cache killer.
49
		$version = $this->plugin->get_version();
50
51
		// User can edit?
52
		$can_edit = current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' );
53
54
		// If user can't edit or rich editing isn't enabled, bail out.
55
		if ( ! $can_edit || ! get_user_option( 'rich_editing' ) ) {
56
			return $plugins;
57
		}
58
59
		// Add our own JavaScript file to TinyMCE's extensions.
60
		$plugins['wordlift']   = plugin_dir_url( dirname( __FILE__ ) ) . 'js/wordlift-reloaded.js?ver=' . $version;
61
		$plugins['wl_tinymce'] = plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/wordlift-admin-tinymce.bundle.js?ver=' . $version;
62
63
		return $plugins;
64
	}
65
66
}
67