Skip to content

Commit e9c80c6

Browse files
release: fixes
### Fixes - Reuse existing generated images before trying to generate new ones on import [PRO] - Updated dependencies - NPS Survey added - Preparation for future BF campaign
2 parents 62a743b + 4524895 commit e9c80c6

File tree

8 files changed

+238
-126
lines changed

8 files changed

+238
-126
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

img/black-friday-banner.png

37 Bytes
Loading

includes/admin/feedzy-rss-feeds-admin.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ public function enqueue_styles_admin() {
128128
wp_enqueue_script( $this->plugin_name . '_telemetry', FEEDZY_ABSURL . 'js/telemetry.js', array(), $this->version, true );
129129
}
130130

131+
if ( 'feedzy_imports' === $screen->post_type && 'edit' === $screen->base ) {
132+
$this->register_survey();
133+
}
134+
131135
if ( 'feedzy_categories' === $screen->post_type ) {
132136
wp_enqueue_script(
133137
$this->plugin_name . '_categories',
@@ -152,6 +156,8 @@ public function enqueue_styles_admin() {
152156
),
153157
)
154158
);
159+
160+
$this->register_survey();
155161
}
156162

157163
if ( 'feedzy_page_feedzy-settings' === $screen->base ) {
@@ -171,6 +177,8 @@ public function enqueue_styles_admin() {
171177
),
172178
)
173179
);
180+
181+
$this->register_survey();
174182
}
175183

176184
$upsell_screens = array( 'feedzy-rss_page_feedzy-settings', 'feedzy-rss_page_feedzy-admin-menu-pro-upsell' );
@@ -195,6 +203,8 @@ public function enqueue_styles_admin() {
195203
)
196204
);
197205
wp_enqueue_style( 'wp-block-editor' );
206+
207+
$this->register_survey();
198208
}
199209
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
200210
wp_enqueue_script( $this->plugin_name . '_on_boarding', FEEDZY_ABSURL . 'js/Onboarding/import-onboarding.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true );
@@ -205,6 +215,9 @@ public function enqueue_styles_admin() {
205215
}
206216

207217
if ( 'feedzy_page_feedzy-support' === $screen->base || ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type ) ) {
218+
219+
$this->register_survey();
220+
208221
wp_enqueue_script( $this->plugin_name . '_feedback', FEEDZY_ABSURL . 'js/FeedBack/feedback.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true );
209222
wp_enqueue_style( 'wp-block-editor' );
210223

@@ -1565,10 +1578,13 @@ public function api_license_status() {
15651578
'spinnerChiefStatus' => false,
15661579
'wordaiStatus' => false,
15671580
'openaiStatus' => false,
1581+
'amazonStatus' => false,
15681582
);
1583+
15691584
if ( ! feedzy_is_pro() ) {
15701585
return $data;
15711586
}
1587+
15721588
if ( apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
15731589
if ( isset( $pro_options['spinnerchief_licence'] ) && 'yes' === $pro_options['spinnerchief_licence'] ) {
15741590
$data['spinnerChiefStatus'] = true;
@@ -1577,11 +1593,119 @@ public function api_license_status() {
15771593
$data['wordaiStatus'] = true;
15781594
}
15791595
}
1596+
15801597
if ( isset( $pro_options['openai_licence'] ) && 'yes' === $pro_options['openai_licence'] ) {
15811598
if ( apply_filters( 'feedzy_is_license_of_type', false, 'business' ) || apply_filters( 'feedzy_is_license_of_type', false, 'agency' ) ) {
15821599
$data['openaiStatus'] = true;
15831600
}
15841601
}
1602+
1603+
if ( ! empty( $pro_options['amazon_access_key'] ) && ! empty( $pro_options['amazon_secret_key'] ) ) {
1604+
$data['amazonStatus'] = true;
1605+
}
15851606
return $data;
15861607
}
1608+
1609+
/**
1610+
* Get the plan category for the product plan ID.
1611+
*
1612+
* @param object $license_data The license data.
1613+
* @return int
1614+
*/
1615+
private static function plan_category( $license_data ) {
1616+
1617+
if ( ! isset( $license_data->plan ) || ! is_numeric( $license_data->plan ) ) {
1618+
return 0; // Free
1619+
}
1620+
1621+
$plan = (int) $license_data->plan;
1622+
$current_category = -1;
1623+
1624+
$categories = array(
1625+
'1' => array(1, 4, 9), // Personal
1626+
'2' => array(2, 5, 8), // Business/Developer
1627+
'3' => array(3, 6, 7, 10), // Agency
1628+
);
1629+
1630+
foreach ( $categories as $category => $plans ) {
1631+
if ( in_array( $plan, $plans, true ) ) {
1632+
$current_category = (int) $category;
1633+
break;
1634+
}
1635+
}
1636+
1637+
return $current_category;
1638+
}
1639+
1640+
/**
1641+
* Get the data used for the survey.
1642+
*
1643+
* @return array
1644+
* @see survey.js
1645+
*/
1646+
public function get_survery_metadata() {
1647+
1648+
$user_id = 'feedzy_';
1649+
$license_data = get_option( 'feedzy_rss_feeds_pro_license_data', array() );
1650+
1651+
if ( ! empty( $license_data->key ) ) {
1652+
$user_id .= $license_data->key;
1653+
} else {
1654+
$user_id .= preg_replace( '/[^\w\d]*/', '', get_site_url() ); // Use a normalized version of the site URL as a user ID for free users.
1655+
}
1656+
1657+
$integration_status = $this->api_license_status();
1658+
1659+
$days_since_install = round( ( time() - get_option( 'feedzy_rss_feeds_install', 0 ) ) / DAY_IN_SECONDS );
1660+
$install_category = 0;
1661+
if ( 0 === $days_since_install || 1 === $days_since_install ) {
1662+
$install_category = 0;
1663+
} elseif ( 1 < $days_since_install && 8 > $days_since_install ) {
1664+
$install_category = 7;
1665+
} elseif ( 8 <= $days_since_install && 31 > $days_since_install ) {
1666+
$install_category = 30;
1667+
} elseif ( 30 < $days_since_install && 90 > $days_since_install ) {
1668+
$install_category = 90;
1669+
} elseif ( 90 <= $days_since_install ) {
1670+
$install_category = 91;
1671+
}
1672+
1673+
return array(
1674+
'userId' => $user_id,
1675+
'attributes' => array(
1676+
'free_version' => $this->version,
1677+
'pro_version' => defined( 'FEEDZY_PRO_VERSION' ) ? FEEDZY_PRO_VERSION : '',
1678+
'openai' => $integration_status['openaiStatus'] ? 'valid' : 'invalid',
1679+
'amazon' => $integration_status['amazonStatus'] ? 'valid' : 'invalid',
1680+
'spinnerchief' => $integration_status['spinnerChiefStatus'] ? 'valid' : 'invalid',
1681+
'wordai' => $integration_status['wordaiStatus'] ? 'valid' : 'invalid',
1682+
'plan' => $this->plan_category( $license_data ),
1683+
'days_since_install' => $install_category,
1684+
'license_status' => ! empty( $license_data->license ) ? $license_data->license : 'invalid',
1685+
),
1686+
);
1687+
}
1688+
1689+
/**
1690+
* Register the survey script.
1691+
*
1692+
* It does register if we are in CI environment.
1693+
*
1694+
* @return void
1695+
*/
1696+
public function register_survey() {
1697+
1698+
if ( defined( 'CYPRESS_TESTING' ) ) {
1699+
return;
1700+
}
1701+
1702+
$survey_handler = apply_filters( 'themeisle_sdk_dependency_script_handler', 'survey' );
1703+
if ( empty( $survey_handler ) ) {
1704+
return;
1705+
}
1706+
1707+
do_action( 'themeisle_sdk_dependency_enqueue_script', 'survey' );
1708+
wp_enqueue_script( $this->plugin_name . '_survey', FEEDZY_ABSURL . 'js/survey.js', array( $survey_handler ), $this->version, true );
1709+
wp_localize_script( $this->plugin_name . '_survey', 'feedzySurveyData', $this->get_survery_metadata() );
1710+
}
15871711
}

includes/admin/feedzy-rss-feeds-import.php

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,22 +1818,25 @@ function( $term ) {
18181818
}
18191819
}
18201820

1821-
// Item image action.
1822-
$import_featured_img = rawurldecode( $import_featured_img );
1823-
$import_featured_img = trim( $import_featured_img );
1824-
$img_action = $this->handle_content_actions( $import_featured_img, 'item_image' );
1825-
// Item image action process.
1826-
$image_url = $img_action->run_action_job( $import_featured_img, $import_translation_lang, $job, $language_code, $item, $image_url );
1827-
1828-
if ( ! empty( $image_url ) ) {
1829-
if ( 'yes' === $import_item_img_url ) {
1830-
// Set external image URL.
1831-
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_url );
1832-
} else {
1833-
// if import_featured_img is a tag.
1834-
$img_success = $this->generate_featured_image( $image_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
1821+
if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $item['item_title'], $new_post_id ) ) {
1822+
// Item image action.
1823+
$import_featured_img = rawurldecode( $import_featured_img );
1824+
$import_featured_img = trim( $import_featured_img );
1825+
$img_action = $this->handle_content_actions( $import_featured_img, 'item_image' );
1826+
// Item image action process.
1827+
$image_url = $img_action->run_action_job( $import_featured_img, $import_translation_lang, $job, $language_code, $item, $image_url );
1828+
1829+
if ( ! empty( $image_url ) ) {
1830+
if ( 'yes' === $import_item_img_url ) {
1831+
// Set external image URL.
1832+
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_url );
1833+
} else {
1834+
// if import_featured_img is a tag.
1835+
$img_success = $this->generate_featured_image( $image_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
1836+
}
18351837
}
18361838
}
1839+
18371840
// Set default thumbnail image.
18381841
if ( ! $img_success && ! empty( $default_thumbnail ) ) {
18391842
$img_success = set_post_thumbnail( $new_post_id, $default_thumbnail );
@@ -1940,6 +1943,30 @@ public function get_job_feed( $options, $import_content = null, $raw_feed_also =
19401943
return $feed_items;
19411944
}
19421945

1946+
/**
1947+
* Reuses an existing featured image if possible.
1948+
*
1949+
* @param int|bool $result The result of the operation. It can be a boolean or an attachment ID.
1950+
* @param string $title_feed The title of the feed.
1951+
* @param int $post_id The post ID.
1952+
*
1953+
* @return bool
1954+
*/
1955+
public function tryReuseExistingFeaturedImage( &$result, $title_feed, $post_id = 0 ) {
1956+
if ( ! function_exists( 'post_exists' ) ) {
1957+
require_once ABSPATH . 'wp-admin/includes/post.php';
1958+
}
1959+
// Find existing attachment by feed title.
1960+
$attachment_id = post_exists( $title_feed, '', '', 'attachment' );
1961+
1962+
if ( ! $attachment_id ) {
1963+
return false;
1964+
}
1965+
1966+
$result = set_post_thumbnail( $post_id, $attachment_id );
1967+
return true;
1968+
}
1969+
19431970
/**
19441971
* Downloads and sets a post featured image if possible.
19451972
*

0 commit comments

Comments
 (0)