Skip to content

Commit

Permalink
Merge branch 'develop' into fix/preview-features
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Mar 3, 2023
2 parents 4f00b77 + 1c1a180 commit 75fedfe
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 76 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"Cypress": "readonly",
"cy": "readonly",
"ajaxurl": "readonly",
"FormData": "readonly"
"FormData": "readonly",
"classifaiMediaVars": "readonly"
},
"extends": ["plugin:@wordpress/eslint-plugin/recommended"]
}
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,64 @@ The service that powers ClassifAI's Recommended Content, Microsoft Azure's Perso

## Installation

### Manual Installation

#### 1. Download or Clone this repo, install dependencies and build.

- `git clone https://github.com/10up/classifai.git && cd classifai`
- `composer install && npm install && npm run build`

#### 2. Activate Plugin

### Installation via Composer

ClassifAI releases can be installed via Composer.

#### 1. Update composer.json

Instruct Composer to install ClassifAI into the plugins directory by adding or modifying the "extra" section of your project's composer.json file to match the following:

```json
"extra": {
"installer-paths": {
"plugins/{$name}": [
"type:wordpress-plugin"
]
}
}
```

Add this repository to composer.json, specifying a release version, as shown below:

```json
"repositories": [
{
"type": "package",
"package": {
"name": "10up/classifai",
"version": "1.8.1",
"type": "wordpress-plugin",
"dist": {
"url": "https://github.com/10up/classifai/archive/refs/tags/1.8.1.zip",
"type": "zip"
}
}
}
]
```

Finally, require the plugin, using the version number you specified in the previous step:

```json
"require": {
"10up/classifai": "1.8.1"
}
```

After you run `composer update`, ClassifAI will be installed in the plugins directory with no build steps needed.

#### 2. Activate Plugin

## Register ClassifAI account

ClassifAI is a sophisticated solution that we want organizations of all shapes and sizes to count on. To keep adopters apprised of major updates and beta testing opportunities, gather feedback, and prioritize common use cases, we're asking for a little bit of information in exchange for a free key. Your information will be kept confidential.
Expand Down
27 changes: 0 additions & 27 deletions classifai.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,33 +175,6 @@ classifai_autorun();
add_action( 'network_admin_notices', 'classifai_dev_notice' );
}

if ( class_exists( 'Puc_v4_Factory' ) ) {
/*
* Enable updates if we have a valid license
*/
$service_manager = new \Classifai\Services\ServicesManager();
$settings = $service_manager->get_settings();

if ( isset( $settings['valid_license'] ) && $settings['valid_license'] ) {
// @codingStandardsIgnoreStart
$updateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/10up/classifai/',
__FILE__,
'classifai'
);

$updateChecker->addResultFilter(
function( $plugin_info, $http_response = null ) {
$plugin_info->icons = array(
'svg' => plugins_url( '/assets/img/icon.svg', __FILE__ ),
);
return $plugin_info;
}
);
// @codingStandardsIgnoreEnd
}
}

/**
* Show dev version notice on ClassifAI pages if necessary.
*/
Expand Down
6 changes: 3 additions & 3 deletions includes/Classifai/Admin/BulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public function can_register() {
}

/**
* @var $save_post_handler SavePostHandler Triggers a classification with Watson
* @var SavePostHandler Triggers a classification with Watson
*/
private $save_post_handler;

/**
* @var $computer_vision ComputerVision
* @var \Classifai\Providers\Azure\ComputerVision
*/
private $computer_vision;

Expand Down Expand Up @@ -81,7 +81,7 @@ public function register_media_bulk_actions( $bulk_actions ) {

if (
'no' !== $settings['enable_image_tagging'] ||
'no' !== $settings['enable_image_captions']
empty( $this->computer_vision->get_alt_text_settings() )
) {
$bulk_actions['scan_image'] = __( 'Scan Image', 'classifai' );
}
Expand Down
107 changes: 107 additions & 0 deletions includes/Classifai/Admin/Update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* ClassifAI Auto Update Integration
*
* @package 10up/classifai
*/

namespace Classifai\Admin;

use Puc_v4_Factory;

/**
* Plugin update class.
*/
class Update {

/**
* The plugin repository URL for retrieving updates.
*
* @var string
*/
public static $repo_url = 'https://github.com/10up/classifai/';

/**
* The update checker object.
*
* @var Puc_v4p13_Plugin_UpdateChecker
*/
protected $updater;

/**
* Check to see if we can register this class.
*
* @return bool
*/
public function can_register() {
return class_exists( '\Puc_v4_Factory' ) && self::license_check();
}

/**
* Prepare the updater and register hooks.
*/
public function register() {
$this->init();

add_filter( 'pre_set_site_transient_update_plugins', [ $this, 'maybe_update' ], 10, 1 );
}

/**
* Initialize the update checker object.
*
* @return void
*/
public function init() {
$this->updater = Puc_v4_Factory::buildUpdateChecker(
self::$repo_url,
CLASSIFAI_PLUGIN,
'classifai'
);

$this->updater->addResultFilter(
function( $plugin_info, $http_response = null ) {
$plugin_info->icons = array(
'svg' => CLASSIFAI_PLUGIN_URL . 'assets/img/icon.svg',
);
return $plugin_info;
}
);
}

/**
* Initialize the auto update if an update is available.
*
* @param object $transient The transient object.
* @return object The modified transient object.
*/
public function maybe_update( $transient ) {
// Check for an updated version
$update = $this->updater->getUpdate();

if ( $update ) {
// If update is available, add it to the transient.
$transient->response[ $update->filename ] = $update->toWpFormat();
} else {
// No update available, get current plugin info.
$update = $this->updater->getUpdateState()->getUpdate();

// Adding the plugin info to the `no_update` property is required
// for the enable/disable auto-update links to appear correctly in the UI.
$transient->no_update[ $update->filename ] = $update;
}

return $transient;
}

/**
* Verify the site has a valid license.
*
* @return boolean True if valid license, false otherwise.
*/
public static function license_check() {
$service_manager = new \Classifai\Services\ServicesManager();
$settings = $service_manager->get_settings();

return isset( $settings['valid_license'] ) && $settings['valid_license'];
}
}
9 changes: 5 additions & 4 deletions includes/Classifai/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function init_admin_helpers() {
'notifications' => new Admin\Notifications(),
'debug_info' => new Admin\DebugInfo(),
'bulk_actions' => new Admin\BulkActions(),
'updater' => new Admin\Update(),
];

foreach ( $this->admin_helpers as $instance ) {
Expand All @@ -154,10 +155,10 @@ public function enqueue_admin_assets() {
'classifai-admin-script',
'ClassifAI',
[
'api_password' => __( 'API Password', 'classifai' ),
'api_key' => __( 'API Key', 'classifai' ),
'use_key' => __( 'Use an API Key instead?', 'classifai' ),
'use_password' => __( 'Use a username/password instead?', 'classifai' ),
'api_password' => __( 'API Password', 'classifai' ),
'api_key' => __( 'API Key', 'classifai' ),
'use_key' => __( 'Use an API Key instead?', 'classifai' ),
'use_password' => __( 'Use a username/password instead?', 'classifai' ),
]
);
}
Expand Down
Loading

0 comments on commit 75fedfe

Please sign in to comment.