Skip to content

Commit

Permalink
Merge pull request #6 from javiercasares/seo-plugins
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
javiercasares authored Nov 4, 2024
2 parents 2667bde + 0202f47 commit 96a2fc9
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 33 deletions.
11 changes: 11 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
== Changelog ==

= 1.1.1 [2024-11-04] =

**Added**

* Configuration option to dismiss other SEO plugin incompatibilities.

**Compatibility**

* WordPress: 4.1 - 6.7
* PHP: 5.6 - 8.4

= 1.1.0 [2024-11-02] =

**Added**
Expand Down
94 changes: 63 additions & 31 deletions noindex-seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Allows adding a meta-tag for robots noindex in specific parts of your WordPress site.
* Requires at least: 4.1
* Requires PHP: 5.6
* Version: 1.1.0
* Version: 1.1.1
* Author: Javier Casares
* Author URI: https://www.javiercasares.com/
* License: GPL-2.0-or-later
Expand Down Expand Up @@ -237,6 +237,15 @@ function noindex_seo_register() {
);
}

register_setting(
'noindexseo',
'noindex_seo_config_seoplugins',
array(
'type' => 'integer',
'default' => 0,
)
);

// Hook to settings update to clear transient cache.
add_action( 'update_option_noindexseo', 'noindex_seo_clear_transient', 10, 2 );
}
Expand All @@ -261,37 +270,43 @@ function noindex_seo_clear_transient() {
* @return void.
*/
function noindex_seo_detect_conflicts() {
// Include the plugin.php file if the function is not available.
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}

// Define an associative array of conflicting plugins: slug/file => real plugin name.
$conflicting_plugins = array(
'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'All in One SEO',
'premium-seo-pack/index.php' => 'Premium SEO Pack',
'seo-by-rank-math/rank-math.php' => 'Rank Math SEO',
'wp-seopress/seopress.php' => 'SEOPress',
'slim-seo/slim-seo.php' => 'Slim SEO',
'squirrly-seo/squirrly.php' => 'Squirrly SEO',
'autodescription/autodescription.php' => 'The SEO Framework',
'wordpress-seo/wp-seo.php' => 'Yoast SEO',
);
$option_config_seoplugins = get_option( 'noindex_seo_config_seoplugins', 0 );

// Iterate through the conflicting plugins to check if any are active.
foreach ( $conflicting_plugins as $plugin_path => $plugin_name ) {
if ( is_plugin_active( $plugin_path ) ) {
// Add an admin notice if a conflicting plugin is active.
add_action(
'admin_notices',
function () use ( $plugin_name ) {
echo '<div class="notice notice-warning is-dismissible"><p>';
// translators: plugin name.
printf( esc_html__( 'noindex SEO has detected that %s is active. This may cause conflicts. Please configure the options accordingly.', 'noindex-seo' ), esc_html( $plugin_name ) );
echo '</p></div>';
}
);
break; // Stop checking after finding the first conflict.
if( ! absint( $option_config_seoplugins ) ) {

// Include the plugin.php file if the function is not available.
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}

// Define an associative array of conflicting plugins: slug/file => real plugin name.
$conflicting_plugins = array(
'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'All in One SEO',
'premium-seo-pack/index.php' => 'Premium SEO Pack',
'seo-by-rank-math/rank-math.php' => 'Rank Math SEO',
'wp-seopress/seopress.php' => 'SEOPress',
'slim-seo/slim-seo.php' => 'Slim SEO',
'squirrly-seo/squirrly.php' => 'Squirrly SEO',
'autodescription/autodescription.php' => 'The SEO Framework',
'wordpress-seo/wp-seo.php' => 'Yoast SEO',
);

// Iterate through the conflicting plugins to check if any are active.
foreach ( $conflicting_plugins as $plugin_path => $plugin_name ) {
if ( is_plugin_active( $plugin_path ) ) {
// Add an admin notice if a conflicting plugin is active.
add_action(
'admin_notices',
function () use ( $plugin_name ) {
echo '<div class="notice notice-warning is-dismissible"><p>';
// translators: plugin name.
printf( esc_html__( 'noindex SEO has detected that %s is active. This may cause conflicts. Please configure the options accordingly.', 'noindex-seo' ), esc_html( $plugin_name ) );
echo '</p></div>';
}
);
break; // Stop checking after finding the first conflict.
}
}
}
}
Expand Down Expand Up @@ -503,11 +518,26 @@ function noindex_seo_admin() {
<?php
settings_fields( 'noindexseo' );
do_settings_sections( 'noindexseo' ); // In case you have sections added later.

echo '<h2>' . esc_html( __( 'General Configuration', 'noindex-seo' ) ) . '</h2>';
echo '<table class="form-table">';
// Get current configuration value.
$option_config_seoplugins = get_option( 'noindex_seo_config_seoplugins', 0 );
echo '<tr>';
echo '<th scope="row"><label for="noindex_seo_config_seoplugins">' . esc_html( __( 'Plugin compatibility', 'noindex-seo' ) ) . '</label></th>';
echo '<td><fieldset>';
echo '<input type="checkbox" id="noindex_seo_config_seoplugins" name="noindex_seo_config_seoplugins" value="1" ' . checked( 1, $option_config_seoplugins, false ) . '> ';
echo '<span class="description">' . esc_html( __( 'Do not display the message of possible incompatibilities with other plugins.', 'noindex-seo' ) ) . '</span>';
echo '</fieldset></td>';
echo '</tr>';
echo '</table>';

echo '<h2>' . esc_html( __( 'SEO Configuration', 'noindex-seo' ) ) . '</h2>';
?>
<p><?php echo esc_html( __( 'Important note: if you have any doubt about any of the following items, it is best not to activate the option as you could lose results in the search engines.', 'noindex-seo' ) ); ?></p>
<?php
foreach ( $sections as $section_id => $section ) {
echo '<h2>' . esc_html( $section['title'] ) . '</h2>';
echo '<h3>' . esc_html( $section['title'] ) . '</h3>';
echo '<table class="form-table">';
foreach ( $section['fields'] as $field_id => $field ) {
// Check for conditional display.
Expand All @@ -532,8 +562,10 @@ function noindex_seo_admin() {
echo '</fieldset></td>';
echo '</tr>';
}

echo '</table>';
}

?>
<?php submit_button(); ?>
</form>
Expand Down
15 changes: 13 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: javiercasares
Tags: seo, noindex
Requires at least: 4.1
Tested up to: 6.7
Stable tag: 1.1.0
Stable tag: 1.1.1
Requires PHP: 5.6
Version: 1.1.0
Version: 1.1.1
License: GPL-2.0-or-later
License URI: https://spdx.org/licenses/GPL-2.0-or-later.html

Expand Down Expand Up @@ -86,6 +86,17 @@ Extract the contents of the ZIP and upload the contents to the `/wp-content/plug

== Changelog ==

= 1.1.1 [2024-11-04] =

**Added**

* Configuration option to dismiss other SEO plugin incompatibilities.

**Compatibility**

* WordPress: 4.1 - 6.7
* PHP: 5.6 - 8.4

= 1.1.0 [2024-11-02] =

**Added**
Expand Down
1 change: 1 addition & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
delete_option( 'noindex_seo_preview' );
delete_option( 'noindex_seo_customize_preview' );
delete_option( 'noindex_seo_time' );
delete_option( 'noindex_seo_config_seoplugins' );
}

0 comments on commit 96a2fc9

Please sign in to comment.