Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Organic/Organic.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,23 @@ public function isEnabled() : bool {
return $this->isEnabled;
}

/**
* Returns true if `SDK Key` and `Site ID` are configured.
* Does not check validity of the values!
*
* @return bool
*/
public function isConfigured() : bool {
return $this->getSdkKey() && $this->getSiteId();
}

/**
* Returns true if Organic integration is enabled and properly configured
*
* @return bool
*/
public function isEnabledAndConfigured() : bool {
return $this->isEnabled() && $this->getSdkKey() && $this->getSiteId();
return $this->isEnabled() && $this->isConfigured();
}

public function adsTxtRedirectionEnabled() : bool {
Expand Down Expand Up @@ -824,7 +834,7 @@ public function syncPost( WP_Post $post ) {
$title = \htmlspecialchars_decode( $post->post_title );
$title = \apply_filters( 'organic_post_title', $title, $post->ID );

$content = \get_post_field( 'content', $post );
$content = \get_post_field( 'post_content', $post );
$content = \apply_filters( 'the_content', $content );
$content = \apply_filters( 'organic_post_content', $content, $post->ID );

Expand Down
2 changes: 1 addition & 1 deletion src/Organic/SimpleConfigSyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ abstract protected function invoke();
*/
public function __invoke( $args ) {
// Only worth trying if the API key is set
if ( ! $this->organic->isEnabledAndConfigured() ) {
if ( ! $this->organic->isConfigured() ) {
$this->organic->warning( 'Cannot sync data without Organic SDK API Key and Site ID' );
return;
}
Expand Down
29 changes: 19 additions & 10 deletions src/organic.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,26 @@ function init_organic_sentry( string $dsn, string $environment ) : ?\Sentry\Stat
getenv( 'ORGANIC_CDN_URL' ) ?: getenv( 'EMPIRE_CDN_URL' )
);

// On update or activation, we need to make sure content is re-synced because of changes to the plugin code
register_activation_hook(
__FILE__,
function () use ( $organic ) {
$resynced_on_version = get_option( 'organic::resynced_on_version', '0.0.0' );
if ( version_compare( '1.14.4', $resynced_on_version, 'gt' ) ) {
$organic->triggerContentResync();
update_option( 'organic::resynced_on_version', \Organic\ORGANIC_PLUGIN_VERSION, false );
}
$is_installed_as_mustuse_plugin = defined( 'WPMU_PLUGIN_DIR' )
&& strpos( __FILE__, WPMU_PLUGIN_DIR ) === 0;

$check_for_resync = function() use ( $organic, $is_installed_as_mustuse_plugin ) {
$option = 'organic::resynced_on_version';
$resynced_on_version = get_option( $option, '0.0.0' );
// Version should be manually incremented when a sync is necessary post-upgrade
if ( version_compare( '1.15.1', $resynced_on_version, 'gt' ) ) {
$organic->triggerContentResync();
update_option( $option, \Organic\ORGANIC_PLUGIN_VERSION, $is_installed_as_mustuse_plugin );
}
);
};

if ( $is_installed_as_mustuse_plugin ) {
// Activation hook is never called for must-use plugins. We need an additional solution.
$check_for_resync();
} else {
// On update or activation, we need to make sure content is re-synced because of changes to the plugin code
register_activation_hook( __FILE__, $check_for_resync );
}

function add_organic_block_category( $categories ) {
return array_merge(
Expand Down