| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Auto Featured Image - Auto Post Thumbnail |
| 4 |
* Plugin URI: https://themeisle.com/plugins/auto-featured-image |
| 5 |
* Description: Automatically sets the Featured Image from the first image in a post — for any post type. Generate images from post titles or search for images natively in Elementor, Gutenberg, and Classic Editor. |
| 6 |
* Version: 5.0.5 |
| 7 |
* Requires PHP: 7.4 |
| 8 |
* Author: Themeisle <contact@themeisle.com> |
| 9 |
* Author URI: https://themeisle.com |
| 10 |
* Text Domain: auto-post-thumbnail |
| 11 |
* WordPress Available: yes |
| 12 |
* Requires License: no |
| 13 |
* Domain Path: /languages |
| 14 |
* |
| 15 |
* @package AutoPostThumbnail |
| 16 |
*/ |
| 17 |
|
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; // Exit if accessed directly. |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
/** |
| 24 |
* Check premium plugin compatibility. |
| 25 |
* |
| 26 |
* - Old pro (<=1.5.0): deactivates pro, shows error notice, returns true (free continues). |
| 27 |
* - Compatible pro (>1.5.0): deactivates free, shows info notice, returns false (free stops). |
| 28 |
* - No pro found: returns true (free continues). |
| 29 |
* |
| 30 |
* @return bool Whether the free plugin should continue loading. |
| 31 |
*/ |
| 32 |
function wpapt_check_premium_compatibility() { |
| 33 |
$premium_paths = [ |
| 34 |
'auto-post-thumbnail-premium/auto-post-thumbnail-premium.php', |
| 35 |
]; |
| 36 |
|
| 37 |
// Also check same-directory path (dev environment). |
| 38 |
$current_dir = basename( __DIR__ ); |
| 39 |
$dev_path = $current_dir . '/auto-post-thumbnail-premium.php'; |
| 40 |
if ( ! in_array( $dev_path, $premium_paths, true ) ) { |
| 41 |
$premium_paths[] = $dev_path; |
| 42 |
} |
| 43 |
|
| 44 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
| 45 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 46 |
} |
| 47 |
|
| 48 |
foreach ( $premium_paths as $premium_path ) { |
| 49 |
$premium_file = WP_PLUGIN_DIR . '/' . $premium_path; |
| 50 |
|
| 51 |
if ( ! file_exists( $premium_file ) ) { |
| 52 |
continue; |
| 53 |
} |
| 54 |
|
| 55 |
// Check if premium plugin is active (handles both single site and multisite). |
| 56 |
$is_active = false; |
| 57 |
if ( is_multisite() ) { |
| 58 |
$active_plugins = get_site_option( 'active_sitewide_plugins', [] ); |
| 59 |
$is_active = isset( $active_plugins[ $premium_path ] ); |
| 60 |
} |
| 61 |
if ( ! $is_active ) { |
| 62 |
$active_plugins = get_option( 'active_plugins', [] ); |
| 63 |
$is_active = in_array( $premium_path, $active_plugins, true ); |
| 64 |
} |
| 65 |
|
| 66 |
if ( ! $is_active ) { |
| 67 |
continue; |
| 68 |
} |
| 69 |
|
| 70 |
$plugin_data = get_plugin_data( $premium_file, false, false ); |
| 71 |
$premium_version = $plugin_data['Version'] ?? '0.0.0'; |
| 72 |
|
| 73 |
if ( version_compare( $premium_version, '1.5.0', '<=' ) ) { |
| 74 |
// Old incompatible pro — deactivate it. |
| 75 |
if ( ! defined( 'WAPT_PLUGIN_THROW_ERROR' ) ) { |
| 76 |
define( 'WAPT_PLUGIN_THROW_ERROR', true ); |
| 77 |
} |
| 78 |
|
| 79 |
if ( ! function_exists( 'deactivate_plugins' ) ) { |
| 80 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 81 |
} |
| 82 |
|
| 83 |
deactivate_plugins( $premium_path ); |
| 84 |
|
| 85 |
$notice = function () { |
| 86 |
echo '<div class="notice notice-error"><p>' . wp_kses_post( |
| 87 |
sprintf( |
| 88 |
/* translators: %1$s: plugin name, %2$s: required plugin. */ |
| 89 |
__( 'The %1$s plugin has been deactivated because it requires %2$s version 5.0.0 or higher. Please update %2$s to restore its functionality.', 'auto-post-thumbnail' ), |
| 90 |
'<strong>' . __( 'Auto Featured Image Premium', 'auto-post-thumbnail' ) . '</strong>', |
| 91 |
'<strong>' . __( 'Auto Featured Image', 'auto-post-thumbnail' ) . '</strong>' |
| 92 |
) |
| 93 |
) . '</p></div>'; |
| 94 |
}; |
| 95 |
|
| 96 |
add_action( 'admin_notices', $notice ); |
| 97 |
add_action( 'network_admin_notices', $notice ); |
| 98 |
|
| 99 |
return true; |
| 100 |
} |
| 101 |
|
| 102 |
// Compatible pro is active — free should not load. |
| 103 |
if ( ! function_exists( 'deactivate_plugins' ) ) { |
| 104 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 105 |
} |
| 106 |
|
| 107 |
deactivate_plugins( plugin_basename( __FILE__ ) ); |
| 108 |
|
| 109 |
add_action( |
| 110 |
'admin_notices', |
| 111 |
function () { |
| 112 |
echo '<div class="notice notice-info is-dismissible"><p>' . esc_html( |
| 113 |
__( 'Auto Featured Image (Free) has been deactivated because Auto Featured Image Pro is already active. No action is needed.', 'auto-post-thumbnail' ) |
| 114 |
) . '</p></div>'; |
| 115 |
} |
| 116 |
); |
| 117 |
|
| 118 |
return false; |
| 119 |
} |
| 120 |
|
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
if ( ! wpapt_check_premium_compatibility() ) { |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
define( 'WAPT_FREE_PATH', __FILE__ ); |
| 130 |
|
| 131 |
require_once 'bootstrap.php'; |
| 132 |
|