Skip to content

Install via Composer

Takahashi Fumiki edited this page May 29, 2023 · 3 revisions

You can use this plugin as a composer library.

If you are a theme developer, this approach might work well.

Install

composer require kunoichi/ga-communicator

Include

From your theme or plugin, include the composer's autoloader.

// This path will be changed depending on your use case.
require __DIR__ . '/vendor/autload.php';

Run Bootstrap

Calling the bootstrap function will register all hooks.

\Kunoichi\GaCommunicator::get_instance();

Now your code is ready to run.

Difference from plugin usage

Some tasks are skipped, and global functions are omitted.

1. Network Installation

If your site is under network, define constant GA_COMMUNICATOR_NETWORK_ACTIVE to true before running Bootstrap.

define( 'GA_COMMUNICATOR_NETWORK_ACTIVE', true );

The constant above will affect:

  • The setting screen will move to Network Admin > Setting.
  • All sites under the network will share the setting.

2. Widget

Composer skips the "popular posts" widget. Register them if you need one.

// Register Widgets.
add_action( 'widgets_init', function() {
	register_widget( \Kunoichi\GaCommunicator\Widgets\PopularPosts::class );
} );

3. i18n

The gettext call is skipped. The po file is under languages directory and load them via locale method. Only ja and en_US is supported.

\Kunoichi\GaCommunicator::get_instance()->locale();