Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffpaul committed Nov 11, 2022
2 parents 89facaf + 82b7548 commit 49acde5
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 51 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [1.3.1] - 2022-11-10
### Changed
- Mapping for `sectionNames` field to reflect Primary Category or first Category (props [@Sidsector9](https://github.com/Sidsector9), [@cadic](https://github.com/cadic), [@jeffpaul](https://github.com/jeffpaul), [@vjayaseelan90](https://github.com/vjayaseelan90), [@dkotter](https://github.com/dkotter) via [#350](https://github.com/globeandmail/sophi-for-wordpress/pull/350), [#363](https://github.com/globeandmail/sophi-for-wordpress/pull/363)).
- Update our configured check to be smarter (props [@dkotter](https://github.com/dkotter), [@vjayaseelan90](https://github.com/vjayaseelan90), [@jeffpaul](https://github.com/jeffpaul) via [#361](https://github.com/globeandmail/sophi-for-wordpress/pull/361)).

### Removed
- Comment out the override settings _for now_ (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#362](https://github.com/globeandmail/sophi-for-wordpress/pull/362)).

### Fixed
- Ensure we have an array of items before iterating over them (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#362](https://github.com/globeandmail/sophi-for-wordpress/pull/362)).
- Ensure we send tracking events when the Yoast featured category data is saved (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#365](https://github.com/globeandmail/sophi-for-wordpress/pull/365)).

## [1.3.0] - 2022-10-28
**Note that this version bumps the minimum WordPress version from 5.6 to 6.0 and adds an integration with the Sophi Override feature.**

Expand Down Expand Up @@ -268,6 +280,7 @@ All notable changes to this project will be documented in this file, per [the Ke
- Initial public release! 🎉

[Unreleased]: https://github.com/globeandmail/sophi-for-wordpress/compare/trunk...develop
[1.3.1]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.2.1...1.3.0
[1.2.1]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.2.0...1.2.1
[1.2.0]: https://github.com/globeandmail/sophi-for-wordpress/compare/1.1.3...1.2.0
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The following acknowledges the Maintainers for this repository, those who have C

The following individuals are responsible for curating the list of issues, responding to pull requests, and ensuring regular releases happen.

[Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez), [Felipe Elia (@felipeelia)](https://github.com/felipeelia).
[Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Darin Kotter (@dkotter)](https://github.com/dkotter).

## Contributors

Expand Down
12 changes: 7 additions & 5 deletions includes/classes/SiteAutomation/EndPoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ public function site_automation( $request ) {
}

$curated_posts_new = [];
foreach ( $curated_posts as $index => $curated_post ) {
$curated_posts_new[ $index ] = $this->get_post_details( $curated_post, $rules );
if ( is_array( $curated_posts ) ) {
foreach ( $curated_posts as $index => $curated_post ) {
$curated_posts_new[ $index ] = $this->get_post_details( $curated_post, $rules );
}
}
$curated_posts = $curated_posts_new;

Expand Down Expand Up @@ -209,8 +211,8 @@ public function site_automation_params() {
*/
public function site_automation_permission(){
$current_user = wp_get_current_user();
if ( ! $current_user->exists() ) {

if ( ! $current_user->exists() ) {
return new \WP_Error(401, __( 'Unauthorised user, please log in.', 'sophi-wp' ) );
}

Expand Down Expand Up @@ -366,4 +368,4 @@ public function site_automation_override_params() {
*/
return apply_filters( 'site_automation_override_params', $params );
}
}
}
13 changes: 7 additions & 6 deletions includes/functions/content-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function send_track_event( $tracker, $post, $action ) {
* @param {Tracker} $tracker Tracker being used.
* @param {string} $post Post object.
* @param {string} $action Publishing action.
*
*
* @return {array} Tracking data to send.
*/
$data = apply_filters_ref_array( 'sophi_cms_tracking_request_data', array( $data, &$tracker, $post, $action ) );
Expand Down Expand Up @@ -224,7 +224,7 @@ function init_tracker() {
* @hook sophi_tracker_emitter_debug
*
* @param {bool} $debug Debug is active.
*
*
* @return {bool} Whether to turn on emitter debug.
*/
$debug = apply_filters( 'sophi_tracker_emitter_debug', false );
Expand Down Expand Up @@ -276,7 +276,7 @@ function get_post_data( $post ) {
'plainText' => wp_strip_all_tags( $content ),
'size' => str_word_count( wp_strip_all_tags( $content ) ),
'allSections' => Utils\get_post_categories_paths( $post->ID ),
'sectionNames' => Utils\get_post_categories( $post->ID ),
'sectionNames' => Utils\get_primary_category( $post->ID ) ? [ Utils\get_primary_category( $post->ID ) ] : [],
'modifiedAt' => gmdate( \DateTime::RFC3339, strtotime( $post->post_modified_gmt ) ),
'tags' => Utils\get_post_tags( $post ),
'url' => $permalink,
Expand Down Expand Up @@ -333,8 +333,9 @@ function maybe_skip_track_event( $data ) {
$transient_name = 'sophi_tracking_request_' . $transient_hash;

// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( isset( $_GET['meta-box-loader'] ) && $_GET['meta-box-loader'] ) {
// Skip if metabox is reloading.
if ( ( isset( $_GET['meta-box-loader'] ) && $_GET['meta-box-loader'] ) &&
! filter_input( INPUT_POST, 'yoast_wpseo_primary_category_term', FILTER_SANITIZE_NUMBER_INT ) ) {
// Skip if metabox is reloading and we're not saving the primary category.
$skip = true;
} elseif ( get_transient( $transient_name ) === $data ) {
// Skip duplicated track within last 10 seconds.
Expand Down Expand Up @@ -367,7 +368,7 @@ function maybe_skip_track_event( $data ) {
*
* @param {boolean} $skip Whether to skip tracking.
* @param {array} $data Data to track.
*
*
* @return {boolean}
*/
return apply_filters( 'sophi_skip_track_event', $skip, $data );
Expand Down
33 changes: 22 additions & 11 deletions includes/functions/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function fields_setup() {
SETTINGS_GROUP,
'collector_settings',
[
'label_for' => 'collector_url',
'label_for' => 'collector_url',
'description' => __( 'Please use URL without http(s) scheme.', 'sophi-wp' ),
]
);
Expand Down Expand Up @@ -200,6 +200,9 @@ function fields_setup() {
]
);

/* // phpcs:ignore
Commenting out the Sophi Override settings for now.
// Add Auth settings section.
add_settings_section(
'sophi_api_auth',
Expand Down Expand Up @@ -241,6 +244,7 @@ function fields_setup() {
'description' => __( 'For example, https://xyz.sophi.io/v1/, please add a slash (/) in the end.', 'sophi-wp' ),
]
);
*/

// Add Advanced settings section.
add_settings_section(
Expand Down Expand Up @@ -325,13 +329,13 @@ function sanitize_settings( $settings ) {
$settings['query_integration'] = 0;
}

if ( empty( $settings['site_automation_url']) ) {
if ( empty( $settings['site_automation_url'] ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
__( 'Site Automation URL is required for Site Automation integration.', 'sophi-wp' )
);
} else if ( ! filter_var( $settings['site_automation_url'], FILTER_VALIDATE_URL ) ) {
} elseif ( ! filter_var( $settings['site_automation_url'], FILTER_VALIDATE_URL ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
Expand All @@ -343,26 +347,30 @@ function sanitize_settings( $settings ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
/* translators: %s is replaced with the tracker URL */
sprintf( __( 'Tracker Address URL is invalid: %s', 'sophi-wp' ), $settings['tracker_address'] )
);
unset( $settings['tracker_address'] );
}

if ( empty( $settings['sophi_override_url']) ) {
/* // phpcs:ignore
Commenting out the Sophi Override settings for now.
if ( empty( $settings['sophi_override_url'] ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
__( 'Sophi Override URL is required for Override actions.', 'sophi-wp' )
);
} else if ( ! filter_var( $settings['sophi_override_url'], FILTER_VALIDATE_URL ) ) {
} elseif ( ! filter_var( $settings['sophi_override_url'], FILTER_VALIDATE_URL ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
__( 'Sophi Override URL is invalid.', 'sophi-wp' )
);
}
*/

if ( empty( $settings['collector_url']) ) {
if ( empty( $settings['collector_url'] ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
Expand All @@ -383,13 +391,16 @@ function sanitize_settings( $settings ) {
);
}

/* // phpcs:ignore
Commenting out the Sophi Override settings for now.
if ( empty( $settings['sophi_override_client_id'] ) || empty( $settings['sophi_override_client_secret'] ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
__( 'Both Client ID and Client Secret are required to generate a token for API.', 'sophi-wp' )
);
}
*/

if ( isset( $settings['client_id'] ) ) {
unset( $settings['client_id'] );
Expand Down Expand Up @@ -506,15 +517,15 @@ function render_select( $args ) {
*
* @return array
*/
function add_action_links ( $actions ) {
if ( ! is_configured() ) {
$action_label = __('Set up your Sophi.io account', 'sophi-wp');
function add_action_links( $actions ) {
if ( ! is_configured( 'collector' ) || ! is_configured( 'automation' ) ) {
$action_label = __( 'Set up your Sophi.io account', 'sophi-wp' );
} else {
$action_label = __('Settings', 'sophi-wp');
$action_label = __( 'Settings', 'sophi-wp' );
}
return array_merge(
[
'<a href="' . admin_url('options-general.php?page=sophi') . '">' . $action_label . '</a>',
'<a href="' . admin_url( 'options-general.php?page=sophi' ) . '">' . $action_label . '</a>',
],
$actions
);
Expand Down
73 changes: 63 additions & 10 deletions includes/functions/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,51 @@ function get_supported_post_types() {
/**
* Check if Sophi is configured or not.
*
* @param string $section Settings section to check for. Default 'all'.
* @return bool
*/
function is_configured() {
function is_configured( $section = 'all' ) {
$settings = get_sophi_settings();

unset( $settings['environment'] );
unset( $settings['query_integration'] );

$settings = array_filter(
$settings,
function( $item ) {
return empty( $item );
}
);
switch ( $section ) {
case 'collector':
$settings = array_filter(
$settings,
function( $item, $key ) {
return in_array( $key, [ 'collector_url', 'tracker_address', 'tracker_client_id' ], true ) && empty( $item );
},
ARRAY_FILTER_USE_BOTH
);
break;
case 'automation':
$settings = array_filter(
$settings,
function( $item, $key ) {
return in_array( $key, [ 'host', 'tenant_id', 'site_automation_url' ], true ) && empty( $item );
},
ARRAY_FILTER_USE_BOTH
);
break;
case 'override':
$settings = array_filter(
$settings,
function( $item, $key ) {
return in_array( $key, [ 'sophi_override_url', 'sophi_override_client_id', 'sophi_override_client_secret' ], true ) && empty( $item );
},
ARRAY_FILTER_USE_BOTH
);
break;
case 'all':
default:
$settings = array_filter(
$settings,
function( $item, $key ) {
return ! in_array( $key, [ 'environment', 'query_integration' ], true ) && empty( $item );
},
ARRAY_FILTER_USE_BOTH
);
break;
}

if ( count( $settings ) > 0 ) {
return false;
Expand Down Expand Up @@ -545,3 +576,25 @@ function get_post_categories( $post_id ) {
function get_wp_sophi_versions() {
return 'wp-' . get_bloginfo( 'version' ) . ':plugin-' . SOPHI_WP_VERSION;
}

/**
* Get the primary term name.
*
* @param string $taxonomy Optional. The taxonomy to get the primary term ID for. Defaults to category.
* @param int $post_id Optional. Post to get the primary term ID for.
*
* @return string
*/
function get_primary_category( $post_id = 0, $taxonomy = 'category' ) {
if ( ! function_exists( 'yoast_get_primary_term' ) || ! yoast_get_primary_term( $taxonomy, $post_id ) ) {
$post_terms = wp_get_post_terms( $post_id, $taxonomy );

if ( is_array( $post_terms ) && count( $post_terms ) > 0 ) {
return $post_terms[0]->name;
} else {
return '';
}
}

return yoast_get_primary_term( $taxonomy, $post_id );
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@globeandmail/sophi-for-wordpress",
"version": "1.3.0",
"version": "1.3.1",
"description": "WordPress VIP-compatible plugin for the Sophi.io Site Automation service.",
"homepage": "https://github.com/globeandmail/sophi-for-wordpress",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
bootstrap="tests/bootstrap.php"
backupGlobals="false"
processIsolation="false"
colors="false">
colors="true">
<testsuites>
<testsuite name="Default">
<directory suffix="Tests.php">./tests/phpunit</directory>
Expand Down
11 changes: 10 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
=== Sophi ===
Contributors: 10up, sophidev
Tags: Sophi, Site Automation, Curator, Collector, AI, Artifical Intelligence, ML, Machine Learning, Content Curation
Requires at least: 6.0
Tested up to: 6.0
Stable tag: 1.3.0
Stable tag: 1.3.1
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -149,6 +151,13 @@ The same [Privacy & Terms that govern The Globe and Mail](https://www.theglobean

== Changelog ==

= 1.3.1 - 2022-11-10 =
* **Changed:** Mapping for `sectionNames` field to reflect Primary Category or first Category (props [@Sidsector9](https://github.com/Sidsector9), [@cadic](https://github.com/cadic), [@jeffpaul](https://github.com/jeffpaul), [@vjayaseelan90](https://github.com/vjayaseelan90), [@dkotter](https://github.com/dkotter) via [#350](https://github.com/globeandmail/sophi-for-wordpress/pull/350), [#363](https://github.com/globeandmail/sophi-for-wordpress/pull/363)).
* **Changed:** Update our configured check to be smarter (props [@dkotter](https://github.com/dkotter), [@vjayaseelan90](https://github.com/vjayaseelan90), [@jeffpaul](https://github.com/jeffpaul) via [#361](https://github.com/globeandmail/sophi-for-wordpress/pull/361)).
* **Removed:** Comment out the override settings _for now_ (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#362](https://github.com/globeandmail/sophi-for-wordpress/pull/362)).
* **Fixed:** Ensure we have an array of items before iterating over them (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#362](https://github.com/globeandmail/sophi-for-wordpress/pull/362)).
* **Fixed:** Ensure we send tracking events when the Yoast featured category data is saved (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#365](https://github.com/globeandmail/sophi-for-wordpress/pull/365)).

= 1.3.0 - 2022-10-28 =
**Note that this version bumps the minimum WordPress version from 5.6 to 6.0 and adds an integration with the Sophi Override feature.**

Expand Down
Loading

0 comments on commit 49acde5

Please sign in to comment.