Skip to content

Commit

Permalink
Detect SEO plugin active
Browse files Browse the repository at this point in the history
  • Loading branch information
someguy9 committed May 19, 2022
1 parent 91621d5 commit 3fd8f0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
36 changes: 30 additions & 6 deletions mightyshare.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: MightyShare
* Plugin URI: https://mightyshare.io/wordpress/
* Description: Automatically generate social share preview images with MightyShare!
* Version: 1.0.1
* Version: 1.0.2
* Text Domain: mightyshare
* Author: MightyShare
* Author URI: https://mightyshare.io
Expand All @@ -13,7 +13,7 @@
exit; // Exit if accessed directly.
}

define( 'MIGHTYSHARE_VERSION', '1.0.1' );
define( 'MIGHTYSHARE_VERSION', '1.0.2' );
define( 'MIGHTYSHARE_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'MIGHTYSHARE_DIR_URI', plugin_dir_path( __FILE__ ) );

Expand Down Expand Up @@ -201,6 +201,14 @@ public function init_settings() {
'display'
);

add_settings_field(
'detected_seo_plugin',
__( 'Detected SEO Plugin', 'mightyshare' ),
array( $this, 'render_detected_seo_plugin_field' ),
'mightyshare',
'display'
);

add_settings_field(
'opengraph',
__( 'Enable Open Graph', 'mightyshare' ),
Expand Down Expand Up @@ -280,14 +288,14 @@ public function render_mightyshare_api_key_field() {
$options = get_option( 'mightyshare' );

// Set default values.
$value_api_key = isset( $options['mightyshare_api_key'] ) ? $options['mightyshare_api_key'] : '';
$value_api_key = isset( $options['mightyshare_api_key'] ) ? $options['mightyshare_api_key'] : '';
$field_type = isset( $options['mightyshare_api_key'] ) ? 'password' : 'text';
$checked = isset( $options['mightyshare_api_key'] ) ? '' : 'checked';
$checked = isset( $options['mightyshare_api_key'] ) ? '' : 'checked';

// Field output.
?>
<input type="<?php echo esc_attr( $field_type ); ?>" name="mightyshare[mightyshare_api_key]" class="regular-text mightyshare_api_key_field" placeholder="<?php echo esc_attr( __( 'API KEY', 'mightyshare' ) ); ?>" id="mightyshare_api_key_field" value="<?php echo esc_attr( $value_api_key ); ?>"> <label><input type="checkbox" onclick="toggleApiKeyFieldMask('.mightyshare_api_key_field')" <?php echo esc_attr( $checked ); ?>> <?php echo wp_kses_post( __( 'Display API Key', 'mightyshare' ) ); ?></label>
<p class="description"><?php echo wp_kses_post( __( 'Your MightyShare.io API Key. <br /><small>Dont\'t have an API Key? <a href="https://mightyshare.io/register" rel="nofollow noopener" target="_blank">Get a free MightyShare API Key</a></small>', 'mightyshare' ) ); ?></p>
<p class="description"><?php echo wp_kses_post( __( 'Your MightyShare.io API Key. <br /><small>Don\'t have an API Key? <a href="https://mightyshare.io/register" rel="nofollow noopener" target="_blank">Get a free MightyShare API Key</a></small>', 'mightyshare' ) ); ?></p>
<?php
}

Expand Down Expand Up @@ -390,6 +398,22 @@ public function render_logo_field() {
<?php
}

public function render_detected_seo_plugin_field() {
if ( in_array( 'wordpress-seo/wp-seo.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) || in_array( 'wordpress-seo-premium/wp-seo-premium.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
?>
Yoast SEO
<?php
} elseif ( in_array( 'seo-by-rank-math/rank-math.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
?>
RankMath
<?php
} else {
?>
None
<?php
}
}

public function render_opengraph_field() {
// Retrieve data from the database.
$options = get_option( 'mightyshare' );
Expand All @@ -398,7 +422,7 @@ public function render_opengraph_field() {
if ( empty( $options ) ) {
$value = 'no';
} else {
$value = ( 'on' === $options['output_opengraph'] ) ? 'yes' : '';
$value = ( ! empty( $options['output_opengraph'] ) && 'on' === $options['output_opengraph'] ) ? 'yes' : '';
}
// Field output.
render_mightyshare_checkbox_field(
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tags: Social Preview, Open Graph, Social Media, Twitter Card, Open Graph Images
Requires at least: 5.4
Tested up to: 6.0
Requires PHP: 7.0
Stable tag: 1.0.1
Stable tag: 1.0.2
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -52,6 +52,10 @@ The MightyShare plugin places a signed MightShare image URL onto your meta tags.

== Changelog ==

= 1.0.2 =
* PHP bug fix.
* Show detected SEO plugin on settings page.

= 1.0.1 =
* Bug fix for plugin install message.

Expand Down

0 comments on commit 3fd8f0d

Please sign in to comment.