| 1 |
<?php |
| 2 |
|
| 3 |
namespace Pronamic\WordPress\PronamicClient; |
| 4 |
|
| 5 |
class Plugin { |
| 6 |
/** |
| 7 |
* Instance of this class. |
| 8 |
* |
| 9 |
* @since 1.1.0 |
| 10 |
* |
| 11 |
* @var Pronamic_WP_Extensions_ExtensionsPlugin |
| 12 |
*/ |
| 13 |
protected static $instance = null; |
| 14 |
|
| 15 |
/** |
| 16 |
* Plugin file |
| 17 |
* |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
public $file; |
| 21 |
|
| 22 |
/** |
| 23 |
* Plugin directory path. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
public $dir_path; |
| 28 |
|
| 29 |
/** |
| 30 |
* Modules. |
| 31 |
* |
| 32 |
* @var array |
| 33 |
*/ |
| 34 |
public $modules; |
| 35 |
|
| 36 |
/** |
| 37 |
* Constructs and initialize Pronamic WordPress Extensions plugin |
| 38 |
* |
| 39 |
* @param string $file |
| 40 |
*/ |
| 41 |
private function __construct( $file ) { |
| 42 |
$this->file = $file; |
| 43 |
$this->dir_path = plugin_dir_path( $file ); |
| 44 |
|
| 45 |
// Actions |
| 46 |
add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); |
| 47 |
|
| 48 |
add_action( 'admin_bar_menu', [ $this, 'admin_bar_menu' ], 100 ); |
| 49 |
|
| 50 |
add_action( 'pronamic_credits', 'pronamic_client_credits' ); |
| 51 |
|
| 52 |
// Filters |
| 53 |
add_filter( 'wp_headers', [ $this, 'wp_headers' ] ); |
| 54 |
|
| 55 |
// Modules. |
| 56 |
$this->modules = [ |
| 57 |
'adminer' => AdminerModule::get_instance( $this ), |
| 58 |
'akismet' => AkismetModule::get_instance( $this ), |
| 59 |
'google-analytics' => GoogleAnalyticsModule::get_instance( $this ), |
| 60 |
'google-tag-manager' => GoogleTagManagerModule::get_instance( $this ), |
| 61 |
'gravityforms' => GravityFormsModule::get_instance( $this ), |
| 62 |
'jetpack' => JetpackModule::get_instance( $this ), |
| 63 |
'phpmailer' => PhpMailerModule::get_instance( $this ), |
| 64 |
'query-monitor' => QueryMonitorModule::get_instance( $this ), |
| 65 |
'scripts' => ScriptsModule::get_instance( $this ), |
| 66 |
'yoast' => YoastModule::get_instance( $this ), |
| 67 |
'complianz' => ComplianzModule::get_instance(), |
| 68 |
]; |
| 69 |
|
| 70 |
// Admin |
| 71 |
if ( is_admin() ) { |
| 72 |
Admin::get_instance( $this ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Plugins loaded. |
| 78 |
* |
| 79 |
* @return void |
| 80 |
*/ |
| 81 |
public function plugins_loaded() { |
| 82 |
load_plugin_textdomain( 'pronamic-client', false, dirname( plugin_basename( $this->file ) ) . '/languages/' ); |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Admin bar menu |
| 87 |
*/ |
| 88 |
public function admin_bar_menu() { |
| 89 |
if ( current_user_can( 'pronamic_client' ) ) { |
| 90 |
global $wp_admin_bar; |
| 91 |
|
| 92 |
$wp_admin_bar->add_menu( |
| 93 |
[ |
| 94 |
'id' => 'pronamic', |
| 95 |
'title' => __( 'Pronamic', 'pronamic-client' ), |
| 96 |
'href' => __( 'https://www.pronamic.eu/', 'pronamic-client' ), |
| 97 |
'meta' => [ |
| 98 |
'target' => '_blank', |
| 99 |
], |
| 100 |
] |
| 101 |
); |
| 102 |
|
| 103 |
$wp_admin_bar->add_menu( |
| 104 |
[ |
| 105 |
'parent' => 'pronamic', |
| 106 |
'id' => 'pronamic_contact', |
| 107 |
'title' => __( 'Contact', 'pronamic-client' ), |
| 108 |
'href' => __( 'https://www.pronamic.eu/contact/', 'pronamic-client' ), |
| 109 |
'meta' => [ |
| 110 |
'target' => '_blank', |
| 111 |
], |
| 112 |
] |
| 113 |
); |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* WordPress headers |
| 119 |
* |
| 120 |
* @param array $headers |
| 121 |
* @return array |
| 122 |
*/ |
| 123 |
public function wp_headers( $headers ) { |
| 124 |
// Extend the headers with a Pronamic powered by header |
| 125 |
$headers['X-Powered-By'] = _x( 'Pronamic | pronamic.eu | info@pronamic.eu', 'x-powered-by', 'pronamic-client' ); |
| 126 |
|
| 127 |
return $headers; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Display/include the specified file |
| 132 |
* |
| 133 |
* @param string $file |
| 134 |
*/ |
| 135 |
public function display( $file ) { |
| 136 |
include plugin_dir_path( $this->file ) . $file; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Return an instance of this class. |
| 141 |
* |
| 142 |
* @since 1.1.0 |
| 143 |
* |
| 144 |
* @return object A single instance of this class. |
| 145 |
*/ |
| 146 |
public static function get_instance( $file = false ) { |
| 147 |
// If the single instance hasn't been set, set it now. |
| 148 |
if ( null === self::$instance ) { |
| 149 |
self::$instance = new self( $file ); |
| 150 |
} |
| 151 |
|
| 152 |
return self::$instance; |
| 153 |
} |
| 154 |
} |
| 155 |
|