Skip to content

Commit

Permalink
Merge pull request #1413 from insideout10/release/3.31.7
Browse files Browse the repository at this point in the history
Release/3.31.7
  • Loading branch information
akshayraje authored Jun 30, 2021
2 parents 4486798 + 0b8186e commit bde8186
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wordlift-plugin",
"description": "WordLift brings the power of Artificial Intelligence to organize content. Attract new readers and get their true attention with top notch semantic seo.",
"private": true,
"version": "3.31.6",
"version": "3.31.7",
"author": "WordLift",
"homepage": "https://wordift.io/",
"license": "GPL-3.0",
Expand Down
2 changes: 1 addition & 1 deletion src-js/webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wordlift-plugin",
"version": "3.31.6",
"version": "3.31.7",
"description": "WordLift Plugin application for the web site public front-end.",
"main": "index.js",
"repository": "https://github.com/insideout10/wordlift-plugin",
Expand Down
8 changes: 4 additions & 4 deletions src-js/webpack/src/common/components/synonyms-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ let SynonymsPanel = props =>

export default compose(
withSelect(select => {
const meta = select("core/editor").getEditedPostAttribute("meta");
if (undefined !== meta && undefined !== meta["_wl_alt_label"]) {
return { altLabels: meta["_wl_alt_label"] };
const meta = select("core/editor").getEditedPostAttribute("_wl_alt_label");
if (undefined !== meta ) {
return { altLabels: meta };
}
return { altLabels: [] };
}),
withDispatch(dispatch => {
return {
onMetaFieldChange: value => {
dispatch("core/editor").editPost({ meta: { _wl_alt_label: value } });
dispatch("core/editor").editPost({ _wl_alt_label: value });
}
};
})
Expand Down
18 changes: 9 additions & 9 deletions src/includes/class-wordlift-entity-type-taxonomy-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ public function init() {
/**
* Register meta _wl_alt_label for use in Gutenberg
*/
register_meta( 'post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array(
'object_subtype' => '',
'show_in_rest' => true,
'single' => false,
'type' => 'string',
'auth_callback' => function () {
return current_user_can( 'edit_posts' );
}
) );
// register_meta( 'post', Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, array(
// 'object_subtype' => '',
// 'show_in_rest' => true,
// 'single' => false,
// 'type' => 'string',
// 'auth_callback' => function () {
// return current_user_can( 'edit_posts' );
// }
// ) );

// see #1364: add custom fields support for CPTs that are valid entity post types in order to be able to
// query for synonyms in Block Editor.
Expand Down
10 changes: 9 additions & 1 deletion src/includes/class-wordlift.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Wordlift\Cache\Ttl_Cache;
use Wordlift\Configuration\Config;
use Wordlift\Duplicate_Markup_Remover\Faq_Duplicate_Markup_Remover;
use Wordlift\Duplicate_Markup_Remover\Videoobject_Duplicate_Remover;
use Wordlift\Entity\Entity_Helper;
use Wordlift\Entity\Entity_No_Index_Flag;
use Wordlift\Entity\Entity_Rest_Service;
Expand Down Expand Up @@ -767,7 +768,7 @@ public function __construct() {
self::$instance = $this;

$this->plugin_name = 'wordlift';
$this->version = '3.31.6';
$this->version = '3.31.7';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
Expand Down Expand Up @@ -1630,6 +1631,13 @@ private function load_dependencies() {
* Create configuration endpoint for webapp to configure.
*/
new Config( $this->admin_setup, $this->key_validation_service, $this->configuration_service );
/**
* @since 3.31.7
* Remove duplicate videoobject.
*/
new Videoobject_Duplicate_Remover();
$synonym_loader = new \Wordlift\Synonym\Loader();
$synonym_loader->init_feature();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/js/dist/block-editor.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-rich-text'), 'version' => '53f09426a509199c8303f0308bcf9283');
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-rich-text'), 'version' => '77de224def1a73a8f57d51790cd7803d');
2 changes: 1 addition & 1 deletion src/js/dist/block-editor.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ You can open your datasets to the public, attaching to it a free or a commercial

== Changelog ==

= 3.31.7 (2021-06-30) =

* Fix [#1410](https://github.com/insideout10/wordlift-plugin/issues/1410): Prevent videoobject duplication in article
* Fix [#1409](https://github.com/insideout10/wordlift-plugin/pull/1409): Synonym fix
* Fix [#1405](https://github.com/insideout10/wordlift-plugin/pull/1405): Fix delete hook

= 3.31.6 (2021-06-15) =

* Enhancement [#1399](https://github.com/insideout10/wordlift-plugin/issues/1399): Videoobject sitemap - Enable on all custom post types
Expand Down
2 changes: 1 addition & 1 deletion src/wordlift.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Plugin Name: WordLift
* Plugin URI: https://wordlift.io
* Description: WordLift brings the power of AI to organize content, attract new readers and get their attention. To activate the plugin <a href="https://wordlift.io/">visit our website</a>.
* Version: 3.31.6
* Version: 3.31.7
* Author: WordLift, Insideout10
* Author URI: https://wordlift.io
* License: GPL-2.0+
Expand Down
9 changes: 7 additions & 2 deletions src/wordlift/dataset/class-sync-post-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ private function register_hooks() {
add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 );
add_action( 'delete_post', array( $this, 'delete_post' ) );

// running this on delete_post wouldnt work because at that time
// entity_url would be deleted, so we cant delete this item from KG.
add_action( 'before_delete_post', array( $this, 'delete_post' ) );

// Remove post when its trashed.
add_action( 'trashed_post', array( $this, 'delete_post' ) );
// Save the post when its untrashed.
add_action( 'untrashed_post', array( $this, 'save_post' ) );


}

public function save_post( $post_id ) {
Expand Down Expand Up @@ -108,7 +113,7 @@ public function delete_post( $post_id ) {

public function do_delete( $post_id ) {
try {
$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id );
$this->sync_service->delete_one( Object_Type_Enum::POST, $post_id, get_post_meta( $post_id, 'entity_url', true ) );
} catch ( \Exception $e ) {
$this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e );
}
Expand Down
13 changes: 9 additions & 4 deletions src/wordlift/dataset/class-sync-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ public function sync_one( $type, $object_id ) {
return $this->sync_many( array( $object ) );
}

public function delete_one( $type, $object_id ) {
$object = $this->sync_object_adapter_factory->create( $type, $object_id );
$uri = $object->get_meta( 'entity_url', true );

/**
* @param $type string Post or User.
* @param $object_id int Post or User id
* @param $uri string Entity uri , This needs to be supplied before deletion, if we
* get it from meta it might not be available.
*
* @return bool
*/
public function delete_one( $type, $object_id, $uri ) {
// Entity URL isn't set, bail out.
if ( empty( $uri ) ) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/wordlift/dataset/class-sync-user-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function delete_user( $user_id ) {

public function do_delete( $user_id ) {
try {
$this->sync_service->delete_one( Object_Type_Enum::USER, $user_id );
$this->sync_service->delete_one( Object_Type_Enum::USER, $user_id, get_user_meta( $user_id, 'entity_url', true ) );
} catch ( \Exception $e ) {
$this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Wordlift\Duplicate_Markup_Remover;

/**
* @author Naveen Muthusamy <[email protected]>
* @since 3.31.7
* Class Videoobject_Duplicate_Remover
* @package Wordlift\Duplicate_Markup_Remover
*/
class Videoobject_Duplicate_Remover {

public function __construct() {
add_filter( 'wl_after_get_jsonld', array( $this, 'wl_after_get_jsonld' ), 10, 2 );
}

/**
* @param $jsonld array The final jsonld.
* @param $post_id int The post id.
*
* @return array Filtered jsonld.
*/
public function wl_after_get_jsonld( $jsonld, $post_id ) {

if ( ! is_array( $jsonld )
|| ! count( $jsonld ) > 1
|| ! array_key_exists( 0, $jsonld ) ) {
// Return early if there are no referenced entities.
return $jsonld;
}

$post_jsonld = array_shift( $jsonld );

// we need to loop through all the items and remove the faq markup.
foreach ( $jsonld as $key => &$value ) {
if ( ! array_key_exists( '@type', $value ) ) {
continue;
}
$type = $value['@type'];

if ( ( is_string( $type ) && $type !== 'Article' )
|| ( is_array( $type ) && ! in_array( 'Article', $type ) ) ) {
continue;
}
// Video doesnt exist, dont try to remove it.
if ( ! array_key_exists( 'video', $value ) ) {
continue;
}
unset( $jsonld[ $key ]['video'] );
}

// Add the post jsonld to front of jsonld array.
array_unshift( $jsonld, $post_jsonld );

return $jsonld;
}


}
24 changes: 24 additions & 0 deletions src/wordlift/synonym/class-loader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace Wordlift\Synonym;

use Wordlift\Common\Loader\Default_Loader;


/**
* @since 3.31.7
* @author Naveen Muthusamy <[email protected]>
*/
class Loader extends Default_Loader {

public function init_all_dependencies() {
new Rest_Field();
}

protected function get_feature_slug() {
return 'add-synonyms';
}

protected function get_feature_default_value() {
return true;
}
}
73 changes: 73 additions & 0 deletions src/wordlift/synonym/class-rest-field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Wordlift\Synonym;

use Wordlift_Entity_Service;

class Rest_Field {

public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_rest_field' ) );
}

public function register_rest_field() {

if ( ! function_exists( 'register_rest_field' ) ) {
return;
}


$post_types = Wordlift_Entity_Service::valid_entity_post_types();

foreach ( $post_types as $post_type ) {

register_rest_field(
$post_type,
\Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY,
array(
'get_callback' => array( $this, 'get_value' ),
'update_callback' => array( $this, 'update_value' )
)
);

}


}

/**
* @param $meta_values array
* @param $post \WP_Post
* @param $meta_key string
*/
public function update_value( $meta_values, $post, $meta_key ) {

if ( ! is_array( $meta_values ) ) {
return;
}
delete_post_meta( $post->ID, Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );

// @todo: check if the keys have to be unique.
$meta_values = array_unique( $meta_values );

foreach ( $meta_values as $item ) {
add_post_meta( $post->ID, \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY, $item );
}
}

/**
* @param $post array Post array.
*
* @return array|mixed
*/
public function get_value( $post ) {
$data = get_post_meta( (int) $post["id"], \Wordlift_Entity_Service::ALTERNATIVE_LABEL_META_KEY );
if ( ! is_array( $data ) ) {
return array();
}

return $data;
}


}
Loading

0 comments on commit bde8186

Please sign in to comment.