Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wp-digital/wp-instagram


https://github.com/wp-digital/wp-instagram

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# WordPress Instagram Basic Display integration

### Description

Enables **Instagram Basic Display API** for developers.

The idea of the plugin is to use [Instagram Basic Display PHP API](https://github.com/espresso-dev/instagram-basic-display-php)
with ability to get access token through WordPress admin panel.

### Install

- Preferable way is to use [Composer](https://getcomposer.org/):

````
composer require innocode-digital/wp-instagram
````

- Alternate way is to clone this repo to `wp-content/plugins/`:

````
cd wp-content/plugins/
git clone [email protected]:innocode-digital/wp-instagram.git
cd wp-instagram/
composer install
````

Activate **WordPress Instagram Basic Display integration** with [WP-CLI](https://make.wordpress.org/cli/handbook/)
`wp plugin activate wp-instagram` or from **Plugins** page.

### Usage

1. Check [Facebook Manual](https://developers.facebook.com/docs/instagram-basic-display-api/getting-started) on how to
create an APP.

2. Add required constants (usually to `wp-config.php`):

````
define( 'INSTAGRAM_CLIENT_ID', '' );
define( 'INSTAGRAM_CLIENT_SECRET', '' );
````

3. Add site auth URL `https://site.com/instagram/auth/` to **Valid OAuth Redirect URIs** in **Basic Display**.

4. Open settings page in WordPress admin panel **Settings** -> **Instagram**
`/wp-admin/options-general.php?page=innocode-instagram`

5. Click on **Log in** button or **Log in as another user** in case when should change
account.

6. Start use [Instagram Basic Display PHP API](https://github.com/espresso-dev/instagram-basic-display-php) through
`innocode_instagram();` function e.g. `innocode_instagram()->getUserProfile();`.

7. (optional) Set site deauth REST API endpoint `https://site.com/wp-json/innocode/v1/instagram/deauth` in
**Deauthorize Callback URL** in **Basic Display**.

### Notes

If site is a part of [Multisite](https://wordpress.org/support/article/create-a-network/)
then main site auth URL should be added in **Valid OAuth Redirect URIs**.
So, plugin should be active on all network or at least on the main site additionally.

Plugin adds daily cron job after authorization. So, please be sure cron functionality works.
The token tries to update 3 days before the expiration, user profile data updated daily.

### Documentation

By default, endpoint auth URL is using `instagram` as endpoint, but it's possible to
change with constant:

````
define( 'INNOCODE_INSTAGRAM_ENDPOINT', 'insta' );
````

---

#### App site

If you want to use one APP for all of your sites where Instagram integration is in use and correctly handle
deauthorization process then this plugin could be installed additionally on a site which will store user IDs and URLs of sites
where these IDs are using, e.g. this could be a site of your company. Then it's needed to set one more constant on all
sites with activated plugin.

````
define( 'INNOCODE_INSTAGRAM_APP_SITE', 'https://app-site.com' );
````

---

It's possible to change full auth URL:

````
add_filter( 'innocode_instagram_redirect_uri', function ( string $url ) {
return $url;
} );
````

---

It's possible to change Instagram permission:

````
add_filter( 'innocode_instagram_scope', function ( array $scope ) {
return $scope; // Default is array containing 'user_profile' and 'user_media'.
} );
````

---

It's possible to change state parameter which is sending with auth request:

````
add_filter( 'innocode_instagram_state', function ( string $state ) {
return $scope; // Default is string in format '$blog_id:$nonce'.
} );
````

---

It's possible to change place where endpoint should be added:

````
add_filter( 'innocode_instagram_endpoint_mask', function ( $mask, $endpoint ) {
return $mask; // Default is EP_ROOT constant.
}, 10, 2 );
````