', $this->messages ); // phpcs:ignore ?>
version );
define( 'RANK_MATH_PRO_FILE', __FILE__ );
define( 'RANK_MATH_PRO_PATH', dirname( RANK_MATH_PRO_FILE ) . '/' );
define( 'RANK_MATH_PRO_URL', plugins_url( '', RANK_MATH_PRO_FILE ) . '/' );
}
/**
* Include the required files.
*/
private function includes() {
include dirname( __FILE__ ) . '/vendor/autoload.php';
}
/**
* Instantiate classes.
*/
private function instantiate() {
new \RankMathPro\Modules();
$this->load_3rd_party();
}
/**
* Load 3rd party modules.
*/
private function load_3rd_party() {
if ( defined( 'ELEMENTOR_VERSION' ) ) {
new \RankMathPro\Elementor\Elementor();
}
add_action(
'after_setup_theme',
function() {
if ( defined( 'ET_CORE' ) ) {
new \RankMathPro\Divi\Divi();
}
},
11
);
}
/**
* Initialize WordPress action hooks.
*/
private function init_actions() {
if ( is_admin() ) {
add_action( 'rank_math/admin/loaded', [ $this, 'init_admin' ], 15 );
}
add_action( 'rest_api_init', [ $this, 'init_rest_api' ] );
add_action( 'plugins_loaded', [ $this, 'init' ], 11 );
new \RankMathPro\Common();
new \RankMathPro\Register_Vars();
}
/**
* Initialize the admin.
*/
public function init_admin() {
new \RankMathPro\Admin\Admin();
}
/**
* Load the REST API endpoints.
*/
public function init_rest_api() {
$controllers = [
new \RankMathPro\Schema\Rest(),
new \RankMathPro\Analytics\Rest(),
new \RankMathPro\Rest\Rest(),
];
foreach ( $controllers as $controller ) {
$controller->register_routes();
}
}
/**
* Initialize.
*/
public function init() {
if ( Helper::is_module_active( 'image-seo' ) ) {
new \RankMathPro\Image_Seo_Pro();
}
if ( Helper::is_module_active( 'bbpress' ) ) {
new \RankMathPro\BBPress();
}
if ( Helper::is_module_active( 'local-seo', false ) ) {
new \RankMathPro\Local_Seo\Local_Seo();
}
if ( Helper::is_module_active( 'analytics' ) ) {
new \RankMathPro\Analytics\Analytics();
}
if ( Helper::is_woocommerce_active() && Helper::is_module_active( 'woocommerce' ) ) {
new \RankMathPro\WooCommerce();
}
if ( Helper::is_module_active( '404-monitor' ) ) {
new \RankMathPro\Monitor_Pro();
}
if ( Helper::is_module_active( 'redirections' ) ) {
new \RankMathPro\Redirections\Redirections();
}
if ( Helper::is_module_active( 'seo-analysis' ) ) {
new \RankMathPro\SEO_Analysis\SEO_Analysis_Pro();
}
if ( function_exists( 'acf' ) && Helper::is_module_active( 'acf' ) ) {
new \RankMathPro\ACF\ACF();
}
if ( Helper::is_module_active( 'content-ai' ) ) {
new \RankMathPro\Content_AI();
}
new \RankMathPro\Plugin_Update\Plugin_Update();
new \RankMathPro\Thumbnail_Overlays();
}
/**
* Initialize plugin for localization.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
*
* Locales found in:
* - WP_LANG_DIR/rank-math/rank-math-LOCALE.mo
* - WP_LANG_DIR/plugins/rank-math-LOCALE.mo
*/
public function localization_setup() {
$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
$locale = apply_filters( 'plugin_locale', $locale, 'rank-math-pro' ); // phpcs:ignore
unload_textdomain( 'rank-math-pro' );
if ( false === load_textdomain( 'rank-math-pro', WP_LANG_DIR . '/plugins/seo-by-rank-math-pro-' . $locale . '.mo' ) ) {
load_textdomain( 'rank-math-pro', WP_LANG_DIR . '/seo-by-rank-math/seo-by-rank-math-pro-' . $locale . '.mo' );
}
load_plugin_textdomain( 'rank-math-pro', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Check if Rank Math plugin is installed on the site.
*
* @return boolean Whether it's installed or not.
*/
public function is_free_version_installed() {
// First check if active, because that is less costly.
if ( $this->is_free_version_activated() ) {
return true;
}
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed_plugins = get_plugins();
return array_key_exists( $this->free_version_plugin_path, $installed_plugins );
}
/**
* Install Rank Math free version from the wordpress.org repository.
*
* @return bool Whether install was successful.
*/
public function install_free_version() {
include_once ABSPATH . 'wp-includes/pluggable.php';
include_once ABSPATH . 'wp-admin/includes/misc.php';
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$plugin_file = 'https://downloads.wordpress.org/plugin/seo-by-rank-math.latest-stable.zip';
$result = $upgrader->install( $plugin_file );
return $result;
}
/**
* Check if Rank Math plugin is activated on the site.
*
* @return boolean Whether it's active or not.
*/
public function is_free_version_activated() {
$active_plugins = get_option( 'active_plugins', [] );
return in_array( $this->free_version_plugin_path, $active_plugins, true );
}
/**
* Checks if WP is in the process of updating the free one.
*
* @return boolean Whether we are in the process of updating the plugin or not.
*/
public function is_free_version_being_updated() {
$action = isset( $_POST['action'] ) && $_POST['action'] != -1 ? $_POST['action'] : '';
$plugins = isset( $_POST['plugin'] ) ? (array) $_POST['plugin'] : [];
if ( empty( $plugins ) ) {
$plugins = isset( $_POST['plugins'] ) ? (array) $_POST['plugins'] : [];
}
$update_plugin = 'update-plugin';
$update_selected = 'update-selected';
$actions = [ $update_plugin, $update_selected ];
if ( ! in_array( $action, $actions, true ) ) {
return false;
}
return in_array( $this->free_version_plugin_path, $plugins, true );
}
/**
* Checks if WP is in the process of deactivating the free one.
*
* @return boolean Whether we are in the process of deactivating the plugin or not.
*/
public function is_free_version_being_deactivated() {
if ( ! is_admin() ) {
return false;
}
$action = isset( $_REQUEST['action'] ) && $_REQUEST['action'] != -1 ? $_REQUEST['action'] : '';
if ( ! $action ) {
$action = isset( $_REQUEST['action2'] ) && $_REQUEST['action2'] != -1 ? $_REQUEST['action2'] : '';
}
$plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
$checked = isset( $_POST['checked'] ) && is_array( $_POST['checked'] ) ? $_POST['checked'] : [];
$deactivate = 'deactivate';
$deactivate_selected = 'deactivate-selected';
$actions = [ $deactivate, $deactivate_selected ];
if ( ! in_array( $action, $actions, true ) ) {
return false;
}
if ( $action === $deactivate && $plugin !== $this->free_version_plugin_path ) {
return false;
}
if ( $action === $deactivate_selected && ! in_array( $this->free_version_plugin_path, $checked, true ) ) {
return false;
}
return true;
}
/**
* Activate Rank Math free version.
*
* @return bool Whether activation was successful or not.
*/
public function activate_free_version() {
return activate_plugin( $this->free_version_plugin_path );
}
/**
* Is free version compatible.
*
* @return bool
*/
public function is_free_version_compatible() {
return defined( 'RANK_MATH_VERSION' ) && version_compare( RANK_MATH_VERSION, $this->rank_math_min_version, '>=' );
}
/**
* Add query arg to activate url.
*
* @param string $url Activate URL.
*/
public function add_query_arg( $url ) {
return add_query_arg( [ 'pro' => 1 ], $url );
}
}
/**
* Returns the main instance of RankMathPro to prevent the need to use globals.
*
* @return RankMathPro
*/
function rank_math_pro() {
return RankMathPro::get();
}
// Start it.
rank_math_pro();