Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

09-11-2021 #1

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Written by Alan Coggins

A Simple plugin to check WC plugin compatibility with Classic Commerce

Version: 0.0.1
### Description

09/09/21
Classic Commerce was forked from WooCommerce 3.5.3.
Any plugins with declaring "WC requires at least" above 3.5.3 may not work with Classic Commerce.
This plugin helps you scan the installed Plugins on your website, to spot them easily.
179 changes: 77 additions & 102 deletions cc-plugin-checker.php
Original file line number Diff line number Diff line change
@@ -1,116 +1,91 @@
<?php
/**
* Plugin Name: CC Plugin Checker
* Description: Check your WC plugins are compatible with Classic Commerce before migrating your site
* Version: 0.0.1
* Author: Alan Coggins
* Author URI: https://simplycomputing.com.au
**/

// Exit if accessed directly.

if ( ! defined( 'ABSPATH' ) ) {
exit;
* The plugin bootstrap file
*
* @package CC_Plugin_Checker
*
* Plugin Name: CC Plugin Checker
* Description: Check your WC plugins are compatible with Classic Commerce before migrating your site
* Version: 1.2.0
* Author: Alan Coggins, bedas
* Author URI: https://simplycomputing.com.au
**/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'pcc_plugin_settings_link', 10, 5 );

function pcc_plugin_settings_link( $links )
{
$url = '/wp-admin/admin.php?page=PCC_Check';

$_link = '<a href="'.$url.'" target="_blank">' . __( 'CHECK NOW', 'domain' ) . '</a>';
/**
* Current plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'CC_PLUGIN_CHECKER_VERSION', '1.2.0' );

$links[] = $_link;
/**
* Define the Plugin basename
*/
define( 'CC_PLUGIN_CHECKER_BASE_NAME', plugin_basename( __FILE__ ) );

return $links;
/**
* The code that runs during plugin activation.
*
* This action is documented in includes/class-cc-plugin-checker-activator.php
* Full security checks are performed inside the class.
*/
function cc_plugin_checker_activate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-cc-plugin-checker-activator.php';
CC_Plugin_Checker_Activator::activate();
}

if ( !class_exists('PCC')) {

Class PCC {

public function __construct() {
//Hook to add admin menu
add_action("admin_menu", array($this,"PCC_Menu_Pages"));
}

//Define 'PCC_Menu_Pages'
function PCC_Menu_Pages() {
add_menu_page( 'CC Plugin Check', 'CC Plugin Check', 'manage_options', 'PCC_Check', array(__CLASS__,'PCC_Check'), 'dashicons-yes', 90);
}

//Define function
public static function PCC_Check() {

echo '<style>
td, th {
border: 1px solid #ddd;
padding: 6px;
font-size: 16px;
}

th {
padding-top: 8px;
padding-bottom: 8px;
text-align: left;
background-color: #666;
color: white;
}

p {
font-size: 16px;
}
span {
color: #b2b2b2;
}
</style>
<br />
<h1>Check Your WC/CC Plugin Compatibility</h1>
<p>Classic Commerce was forked from WooCommerce 3.5.3.<br />Any plugins with a rating of "WC requires at least" that is more than 3.5.3 may not work with Classic Commerce.</p>
<table>
<tr>
<th>Plugin name</th>
<th>Current version</th>
<th>WC requires at least</th>
<th>WC tested up to</th>
</tr>';

$plugin=get_plugins();

foreach($plugin as $key => $plug) {

$PluginName = $plug['Name'];
$PluginSlug = $plug['TextDomain'];
$PluginCurrentVersion = $plug['Version'];
$PluginPath = WP_PLUGIN_DIR . '/' . $key;

$PluginDetails = get_plugin_data($PluginPath);
/**
* The code that runs during plugin deactivation.
*
* This action is documented in includes/class-cc-plugin-checker-deactivator.php
* Full security checks are performed inside the class.
*/
function cc_plugin_checker_deactivate() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-cc-plugin-checker-deactivator.php';
CC_Plugin_Checker_Deactivator::deactivate();
}

$RequiresAtLeast = $PluginDetails['WC requires at least'];
if ($RequiresAtLeast === '') {
$RequiresAtLeast = '<span>No WC tag</span>';
}
/**
* The code that runs during plugin uninstall.
*
* This action is documented in includes/class-cc-plugin-checker-uninstall.php
* Full security checks are performed inside the class.
*/
function cc_plugin_checker_uninstall() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-cc-plugin-checker-uninstall.php';
CC_Plugin_Checker_Uninstall::uninstall();
}

$TestedUpTo = $PluginDetails['WC tested up to'];
if ($TestedUpTo === '') {
$TestedUpTo = '<span>No WC tag</span>';
}
register_activation_hook( __FILE__, 'cc_plugin_checker_activate' );
register_deactivation_hook( __FILE__, 'cc_plugin_checker_deactivate' );
register_uninstall_hook( __FILE__, 'cc_plugin_checker_uninstall' );

echo '<tbody>
<tr>
<td>'.$PluginName.'</td>
<td>'.$PluginCurrentVersion.'</td>
<td>'.$RequiresAtLeast.'</td>
<td>'.$TestedUpTo.'</td>
</tr>';
}
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-cc-plugin-checker.php';

echo '</tbody>
</table>';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* Generally you will want to hook this function, instead of callign it globally.
* However since the purpose of your plugin is not known until you write it, we include the function globally.
*
* @since 1.0.0
*/
function cc_plugin_checker_run() {

new CC_Plugin_Checker();

}
}
}

new PCC();
add_action( 'init', 'cc_plugin_checker_run' );
177 changes: 177 additions & 0 deletions includes/class-cc-plugin-checker-activator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php
/**
* Fired during plugin activation
*
* @link https://example.com
* @since 1.0.0
*
* @package CC_Plugin_Checker
* @subpackage CC_Plugin_Checker/includes
*/

/**
* Fired during plugin activation.
*
* This class defines all code necessary to run during the plugin's activation.
*
* @todo This should probably be in one class together with Deactivator Class.
* @since 1.0.0
* @package CC_Plugin_Checker
* @subpackage CC_Plugin_Checker/includes
* @author Your Name <email@example.com>
*/
class CC_Plugin_Checker_Activator {

/**
* The $_REQUEST during plugin activation.
*
* @since 1.0.0
* @access private
* @var array $request The $_REQUEST array during plugin activation.
*/
private static $request = array();

/**
* The $_REQUEST['plugin'] during plugin activation.
*
* @since 1.0.0
* @access private
* @var string $plugin The $_REQUEST['plugin'] value during plugin activation.
*/
private static $plugin = CC_PLUGIN_CHECKER_BASE_NAME;

/**
* The $_REQUEST['action'] during plugin activation.
*
* @since 1.0.0
* @access private
* @var array $action The $_REQUEST[action] value during plugin activation.
*/
private static $action = 'activate';

/**
* Activate the plugin.
*
* Checks if the plugin was (safely) activated.
* Place to add any custom action during plugin activation.
*
* @since 1.0.0
*/
public static function activate() {

if ( false === self::get_request()
|| false === self::validate_request( self::$plugin )
|| false === self::check_caps()
) {
if ( isset( $_REQUEST['plugin'] ) ) {
if ( ! check_admin_referer( 'activate-plugin_' . self::$request['plugin'] ) ) {
exit;
}
} elseif ( isset( $_REQUEST['checked'] ) ) {
if ( ! check_admin_referer( 'bulk-plugins' ) ) {
exit;
}
}
}

$active_plugins = get_option( 'active_plugins' );
$required_plugins = array(
'classic-commerce/classic-commerce.php',
'woocommerce/woocommerce.php',
);

if ( empty( array_intersect( $required_plugins, $active_plugins ) ) ) {
// Stop activation redirect and show error.
wp_die( 'Sorry, but this plugin requires either the Classic Commerce Plugin or WooCommerce Plugin to be installed and active. <br><a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">&laquo; Return to Plugins</a>' );
}

}

/**
* Get the request.
*
* Gets the $_REQUEST array and checks if necessary keys are set.
* Populates self::request with necessary and sanitized values.
*
* @since 1.0.0
* @return bool|array false or self::$request array.
*/
private static function get_request() {

if ( ! empty( $_REQUEST )
&& isset( $_REQUEST['_wpnonce'] )
&& isset( $_REQUEST['action'] )
) {
if ( isset( $_REQUEST['plugin'] ) ) {
if ( false !== wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'activate-plugin_' . sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) ) ) {

self::$request['plugin'] = sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) );
self::$request['action'] = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );

return self::$request;

}
} elseif ( isset( $_REQUEST['checked'] ) ) {
if ( false !== wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'bulk-plugins' ) ) {

self::$request['action'] = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
self::$request['plugins'] = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['checked'] ) );

return self::$request;

}
}
} else {

return false;
}

}

/**
* Validate the Request data.
*
* Validates the $_REQUESTed data is matching this plugin and action.
*
* @since 1.0.0
* @param string $plugin The Plugin folder/name.php.
* @return bool false if either plugin or action does not match, else true.
*/
private static function validate_request( $plugin ) {

if ( $plugin === self::$request['plugin']
&& 'activate' === self::$request['action']
) {

return true;

} elseif ( 'activate-selected' === self::$request['action']
&& in_array( $plugin, self::$request['plugins'] )
) {
return true;
}

return false;

}

/**
* Check Capabilities.
*
* We want no one else but users with activate_plugins or above to be able to active this plugin.
*
* @since 1.0.0
* @return bool false if no caps, else true.
*/
private static function check_caps() {

if ( current_user_can( 'activate_plugins' ) ) {
return true;
}

return false;

}

}

Loading