Skip to content

Commit

Permalink
Updated free plugin
Browse files Browse the repository at this point in the history
* Deactivate pro plugin when activating free
  • Loading branch information
ajaydsouza committed May 24, 2024
1 parent 0844fbf commit 6ed0227
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 124 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
[![Required PHP](https://img.shields.io/wordpress/plugin/required-php/contextual-related-posts?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)
[![Active installs](https://img.shields.io/wordpress/plugin/installs/contextual-related-posts?style=flat-square)](https://wordpress.org/plugins/contextual-related-posts/)

__Requires:__ 5.9
__Requires:__ 6.2

__Tested up to:__ 6.4
__Tested up to:__ 6.5

__Requires PHP:__ 7.4

Expand Down Expand Up @@ -47,12 +47,25 @@ With Contextual Related Posts, you can easily boost your site's traffic, reduce
* __Customisable output__: Display post excerpts in the related posts list. You can set the length of the excerpt in words and also strip HTML tags if needed. Customise the HTML tags and attributes used for displaying the output of the related posts list. For example, you can use an ordered or unordered list, a div container, a span element, etc.
* __Extendable code__: Contextual Related Posts has many filters and actions that allow developers to easily add features, modify outputs, or integrate with other plugins.

### Features in Contextual Related Posts Pro

[CRP Pro](https://webberzone.com/plugins/contextual-related-posts/pro/) enhances your experience with an advanced query block, offering more precise customisation options, additional shortcode functionalities, and enhanced meta box settings.

* [Advanced Algorith](https://webberzone.com/support/knowledgebase/contextual-related-posts-algorithm/): Set the relative weight of the post title, post content and post excerpt. This feature overrides the default equal weight algorithm of the free version and provides a greater degree of fine-tuning.
* [Query Loop Block](https://webberzone.com/support/knowledgebase/contextual-related-posts-blocks/#contextual-related-posts-query-loop-block): An advanced block that allows you to display the related posts based on specified parameters. You can use the pre-built block patterns or create your own block patterns for use within posts or the site editor.
* [Extra shortcode parameters](https://webberzone.com/support/knowledgebase/contextual-related-posts-shortcode/): Additional parameters for the shortcode that allow you to customise the output of the related posts list.
* [Additional Metabox settings](https://webberzone.com/support/knowledgebase/contextual-related-posts-metabox/): Additional settings in the post edit screen that allow you to customise the related posts output for each post.

### mySQL FULLTEXT indices

On activation, the plugin creates three mySQL FULLTEXT indices (or indexes) that are then used to find the related posts in the `*_posts`. These are for `post_content`, `post_title` and `(post_title,post_content)`. If you're running a multisite installation, then this is created for each of the blogs on activation. All these indices occupy space in your mySQL database but are essential for the plugin to run.
On activation, the plugin creates three mySQL FULLTEXT indices (or indexes) that are then used to find the related posts in the `*_posts`. These are for `post_content`, `post_title` and `(post_title,post_content)`. The Pro version also has an index for `post_excerpt`.

If you're running a multisite installation, then this is created for each of the blogs on activation. All these indices occupy space in your mySQL database but are essential for the plugin to run.

You have two sets of options in the settings page which allows you to remove these indices when you deactivate or delete the plugin. The latter is true by default.

If you do not wish to use these indices, you can disable contextual matching in the settings page. You will need to turn on related posts by category, tags and/or custom taxonomies.

### GDPR

Contextual Related Posts is GDPR compliant as it doesn't collect any personal data about your visitors when installed out of the box. All posts are processed on your site and not sent to any external service.
Expand Down
68 changes: 68 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,74 @@

This is an archive of older changelog entries. Most recent entries are maintained in readme.txt

= 3.4.1 =

* Bug fix:
* Fixed Request-URI Too Long error when searching for pages/posts
* Related Posts block threw an error when using on the widgets page

= 3.4.0 =

* Features:
* Bulk edit posts, pages and custom post types to add the manual relatd posts and/or exclude posts from the related posts list
* New argument `include_words` to include posts that match the words in the title and/or content.

* Enhancements/Modifications:
* The Manual Related Posts field in the meta box allows a user to live search for related posts
* Caching of the entire HTML output is enabled by default. You can disable it in the settings page. This will reduce the number of database queries and improve performance. If you have customised the output, you will need to clear the cache for the changes to take effect. Applies to new installs and when you reset the settings
* The plugin no longer check for pre v2.5 settings key
* The Media Handler will check the title of the image in case the alt tag text is empty before defaulting to the post title
* All the inbuilt styles have been updated for the `a` tags to have `:focus-visible` declared for accessibility
* The `Heading of posts` setting will now use `<h2>` instead of `<h3>` for the heading by default

* Bug Fixes:
* The post cache was not always cleared when a post was updated

* Deprecated:
* `get_crp_posts_id` has been completed deprecated and will use `get_crp_posts` instead. The function will continue to work but will be removed in a future version

= 3.3.4 =

Release post: [https://webberzone.com/blog/contextual-related-posts-v3-3-0/](https://webberzone.com/blog/contextual-related-posts-v3-3-0/)

* Enhancements/Modifications:
* When displaying the post thumbnail, the Media Handler will first use the image's alt tag set in the Media editor. If alt tag is empty, then it will use the post title as a fallback. Filter `crp_thumb_use_image_alt` and set it to false to not use the alt tag. Filter `crp_thumb_alt_fallback_post_title` and set it to false to disable the alt tag
* Orderby clause modified to ensure compatibility if any other plugin rewrites the WP_Query fields

* Bug Fixes:
* Fix duplicate display of related posts when using reusable blocks or a plugin that inserts pages
* `meta_query` argument was ignored

= 3.3.3 =

* Fixes permission issues with HTML settings

= 3.3.2 =

* Clearing cache security fix

= 3.3.1 =

* Security fix in block

= 3.3.0 =

* Features:
* Related posts block allows you to set a custom header above the related posts. Leave blank to get the one from the main settings page.
* New option "Related Meta Keys" under the List Tuning tab. You can enter a comma-separted list of meta keys. Posts that match the same value of the meta key are displayed before the other related posts.

* Enhancements/modifications:
* If the number of "Manual related posts" is greater than the number of related posts, then the database query is bypassed drastically improving perfomance
* Moved Related Posts Tools page under Tools menu
* Related Posts block is now wrapped in `Disabled` tags to prevent accidental clicking of links in the block editor

* Bug fixes:
* Thumb width and height defaults to 150 in case the settings are missing
* Setting the style to be text_only didn't enforce no thumbnail

* Developer:
* New filters: `crp_query_date_query`, `crp_query_meta_query`, `crp_query_meta_query_relation`

= 3.2.3 =

Release post: [https://webberzone.com/blog/contextual-related-posts-v3-2-0/](https://webberzone.com/blog/contextual-related-posts-v3-2-0/)
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "webberzone/contextual-related-posts",
"description": "Add related posts to your WordPress site with inbuilt caching. Supports thumbnails, shortcodes, widgets and custom post types!",
"version": "3.5.0",
"type": "wordpress-plugin",
"keywords": [
"related posts",
Expand Down
38 changes: 14 additions & 24 deletions contextual-related-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
* @copyright 2009-2024 Ajay D'Souza
*
* @wordpress-plugin
* Plugin Name: Contextual Related Posts
* Plugin Name: Contextual Related Posts Pro
* Plugin URI: https://webberzone.com/plugins/contextual-related-posts/
* Description: Display related posts on your website or in your feed. Increase reader retention and reduce bounce rates
* Version: 3.5.0-beta4
* Version: 3.5.0-beta5
* Author: WebberZone
* Author URI: https://webberzone.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: contextual-related-posts
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/WebberZone/contextual-related-posts/
*/
*
*/

Check warning on line 27 in contextual-related-posts.php

View workflow job for this annotation

GitHub Actions / PHPCS check

Found precision alignment of 1 spaces.

Check failure on line 27 in contextual-related-posts.php

View workflow job for this annotation

GitHub Actions / PHPCS check

Expected 1 space before asterisk; 2 found

Check failure on line 27 in contextual-related-posts.php

View workflow job for this annotation

GitHub Actions / PHPCS check

Additional blank lines found at end of doc comment

namespace WebberZone\Contextual_Related_Posts;

Expand Down Expand Up @@ -102,28 +103,17 @@
// Load the autoloader.
require_once CRP_PLUGIN_DIR . 'includes/autoloader.php';

/**
* The code that runs during plugin activation.
*
* @since 3.5.0
*
* @param bool $network_wide Whether the plugin is being activated network-wide.
*/
function activate( $network_wide ) {
\WebberZone\Contextual_Related_Posts\Admin\Activator::activation_hook( $network_wide );
}
register_activation_hook( __FILE__, __NAMESPACE__ . '\activate' );

/**
* The main function responsible for returning the one true WebberZone Snippetz instance to functions everywhere.
*
* @since 3.5.0
*/
function load() {
\WebberZone\Contextual_Related_Posts\Main::get_instance();
if ( ! function_exists( __NAMESPACE__ . '\load' ) ) {
/**
* The main function responsible for returning the one true WebberZone Snippetz instance to functions everywhere.
*
* @since 3.5.0
*/
function load() {
\WebberZone\Contextual_Related_Posts\Main::get_instance();
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load' );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\load' );


/*
*----------------------------------------------------------------------------
Expand Down
Binary file not shown.
Binary file added includes/admin/images/crp-pro-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified includes/admin/images/x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions includes/admin/settings/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

?>
<div class="postbox-container">
<?php if ( crp_freemius()->is_not_paying() ) { ?>
<?php if ( ! crp_freemius()->is_paying() ) { ?>
<div id="pro-upgrade-banner">
<div class="inside" style="text-align: center">
<a href="https://webberzone.com/plugins/contextual-related-posts/pro/" target="_blank"><img src="<?php echo esc_url( CRP_PLUGIN_URL . 'includes/admin/images/contextual-related-posts-pro-banner.jpg' ); ?>" alt="<?php esc_html_e( 'Contextual Related Posts Pro - Coming soon. Sign up to find out more', 'contextual-related-posts' ); ?>" width="300" height="300" style="max-width: 100%;" /></a>
<a href="https://webberzone.com/plugins/contextual-related-posts/pro/" target="_blank"><img src="<?php echo esc_url( CRP_PLUGIN_URL . 'includes/admin/images/crp-pro-banner.png' ); ?>" alt="<?php esc_html_e( 'Contextual Related Posts Pro - Coming soon. Sign up to find out more', 'contextual-related-posts' ); ?>" width="300" height="300" style="max-width: 100%;" /></a>
</div>
</div>
<?php } ?>

<?php if ( ! crp_freemius()->is_paying() ) { ?>
<div id="donatediv" class="postbox meta-box-sortables">
<h2 class='hndle'><span><?php esc_attr_e( 'Support the development', 'contextual-related-posts' ); ?></span></h2>

Expand All @@ -37,6 +38,7 @@
</div><!-- /#donate-form -->
</div><!-- /.inside -->
</div><!-- /.postbox -->
<?php } ?>

<div id="qlinksdiv" class="postbox meta-box-sortables">
<h2 class='hndle metabox-holder'><span><?php esc_html_e( 'Quick links', 'contextual-related-posts' ); ?></span></h2>
Expand Down
35 changes: 18 additions & 17 deletions includes/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

namespace WebberZone\Contextual_Related_Posts;

use WebberZone\Contextual_Related_Posts\Admin\Activator;
use WebberZone\Contextual_Related_Posts\Frontend\Display;

if ( ! defined( 'WPINC' ) ) {
exit;
}

/**
* Main plugin class.
*
Expand Down Expand Up @@ -92,7 +91,6 @@ public static function get_instance() {
self::$instance = new self();
self::$instance->init();
}

return self::$instance;
}

Expand All @@ -115,9 +113,7 @@ private function init() {
$this->styles = new Frontend\Styles_Handler();
$this->shortcodes = new Frontend\Shortcodes();
$this->blocks = new Frontend\Blocks\Blocks();

$this->hooks();

if ( is_admin() ) {
$this->admin = new Admin\Admin();
}
Expand All @@ -136,7 +132,12 @@ public function hooks() {
add_filter( 'the_excerpt_rss', array( $this, 'content_filter' ), \crp_get_option( 'content_filter_priority' ) );
add_filter( 'the_content_feed', array( $this, 'content_filter' ), \crp_get_option( 'content_filter_priority' ) );
add_action( 'parse_query', array( $this, 'parse_query' ) );
add_action( 'activated_plugin', array( $this, 'deactivate_other_instances' ) );
add_action(
'activated_plugin',
array( $this, 'activated_plugin' ),
10,
2
);
add_action( 'pre_current_active_plugins', array( $this, 'plugin_deactivated_notice' ) );
}

Expand All @@ -155,8 +156,9 @@ public function initiate_plugin() {
* @since 3.5.0
*/
public function register_widgets() {
register_widget( '\WebberZone\Contextual_Related_Posts\Frontend\Widgets\Related_Posts_Widget' );
register_widget( '\\WebberZone\\Contextual_Related_Posts\\Frontend\\Widgets\\Related_Posts_Widget' );
}

/**
* Function to register our new routes from the controller.
*
Expand Down Expand Up @@ -198,29 +200,27 @@ public function parse_query( $query ) {
*
* @since 3.5.0
*
* @param string $plugin The plugin being activated.
* @param string $plugin The plugin being activated.
* @param bool $network_wide Whether the plugin is being activated network-wide.
*/
public function deactivate_other_instances( $plugin ) {
public function activated_plugin( $plugin, $network_wide ) {
if ( ! in_array( $plugin, array( 'contextual-related-posts/contextual-related-posts.php', 'contextual-related-posts-pro/contextual-related-posts.php' ), true ) ) {
return;
}

Activator::activation_hook( $network_wide );
$plugin_to_deactivate = 'contextual-related-posts/contextual-related-posts.php';
$deactivated_notice_id = '1';

// If we just activated the free version, deactivate the pro version.
if ( $plugin === $plugin_to_deactivate ) {
$plugin_to_deactivate = 'contextual-related-posts-pro/contextual-related-posts.php';
$deactivated_notice_id = '2';
}

if ( is_multisite() && is_network_admin() ) {
$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
$active_plugins = array_keys( $active_plugins );
} else {
$active_plugins = (array) get_option( 'active_plugins', array() );
}

foreach ( $active_plugins as $plugin_basename ) {
if ( $plugin_to_deactivate === $plugin_basename ) {
set_transient( 'crp_deactivated_notice_id', $deactivated_notice_id, 1 * HOUR_IN_SECONDS );
Expand All @@ -240,18 +240,19 @@ public function plugin_deactivated_notice() {
if ( ! in_array( $deactivated_notice_id, array( 1, 2 ), true ) ) {
return;
}

$message = __( "Contextual Related Posts and Contextual Related Posts PRO should not be active at the same time. We've automatically deactivated Contextual Related Posts.", 'contextual-related-posts' );
if ( 2 === $deactivated_notice_id ) {
$message = __( "Contextual Related Posts and Contextual Related Posts PRO should not be active at the same time. We've automatically deactivated Contextual Related Posts PRO.", 'contextual-related-posts' );
}

?>
<div class="updated" style="border-left: 4px solid #ffba00;">
<p><?php echo esc_html( $message ); ?></p>
<p>
<?php
echo esc_html( $message );
?>
</p>
</div>
<?php

delete_transient( 'crp_deactivated_notice_id' );
}
}
1 change: 0 additions & 1 deletion includes/load-freemius.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Initialize Freemius SDK.
*/
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"includes",
"languages",
"README.md",
"package.json",
"composer.json",
"contextual-related-posts.php",
"index.php",
"uninstaller.php",
Expand All @@ -35,11 +35,11 @@
"wpml-config.xml"
],
"devDependencies": {
"@wordpress/prettier-config": "^3.14.0",
"@wordpress/scripts": "^27.8.0"
"@wordpress/prettier-config": "^3.15.0",
"@wordpress/scripts": "^27.9.0"
},
"dependencies": {
"@wordpress/icons": "^9.48.0",
"@wordpress/icons": "^9.49.0",
"uuid": "^9.0.1"
}
}
Loading

0 comments on commit 6ed0227

Please sign in to comment.