*/
namespace RankMath\Admin;
use RankMath\Runner;
use RankMath\Helper;
use RankMath\Traits\Ajax;
use RankMath\Traits\Hooker;
use MyThemeShop\Helpers\Str;
use MyThemeShop\Helpers\Param;
use MyThemeShop\Helpers\Conditional;
defined( 'ABSPATH' ) || exit;
/**
* Admin class.
*
* @codeCoverageIgnore
*/
class Admin implements Runner {
use Hooker, Ajax;
/**
* Register hooks.
*/
public function hooks() {
$this->action( 'init', 'flush', 999 );
$this->filter( 'user_contactmethods', 'update_user_contactmethods' );
$this->action( 'save_post', 'canonical_check_notice' );
$this->action( 'wp_dashboard_setup', 'add_dashboard_widgets' );
$this->action( 'cmb2_save_options-page_fields', 'update_is_configured_value', 10, 2 );
// AJAX.
$this->ajax( 'is_keyword_new', 'is_keyword_new' );
$this->ajax( 'save_checklist_layout', 'save_checklist_layout' );
$this->ajax( 'deactivate_plugins', 'deactivate_plugins' );
}
/**
* Flush the rewrite rules once if the rank_math_flush_rewrite option is set.
*/
public function flush() {
if ( get_option( 'rank_math_flush_rewrite' ) ) {
flush_rewrite_rules();
delete_option( 'rank_math_flush_rewrite' );
}
}
/**
* Add Facebook and Twitter as user contact methods.
*
* @param array $contactmethods Current contact methods.
* @return array New contact methods with extra items.
*/
public function update_user_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = esc_html__( 'Twitter username (without @)', 'rank-math' );
$contactmethods['facebook'] = esc_html__( 'Facebook profile URL', 'rank-math' );
return $contactmethods;
}
/**
* Register dashboard widget.
*/
public function add_dashboard_widgets() {
wp_add_dashboard_widget( 'rank_math_dashboard_widget', esc_html__( 'Rank Math', 'rank-math' ), [ $this, 'render_dashboard_widget' ] );
}
/**
* Render dashboard widget.
*/
public function render_dashboard_widget() {
?>
';
$is_use_fk = 'focus_keywords' === Helper::get_settings( 'titles.pt_' . get_post_type() . '_ls_use_fk' );
foreach ( $suggestions as $suggestion ) {
$label = $suggestion['title'];
if ( $is_use_fk && ! empty( $suggestion['focus_keywords'] ) ) {
$label = $suggestion['focus_keywords'][0];
}
$output .= sprintf(
'
',
esc_attr( json_encode( $suggestion['focus_keywords'] ) ),
$suggestion['url'], $suggestion['title'], $label,
esc_attr__( 'Copy Link URL to Clipboard', 'rank-math' ),
esc_attr__( 'Insert Link in Content', 'rank-math' ),
esc_attr( $label )
);
}
$output .= '
';
return $output;
}
/**
* Updates the is_configured value.
*
* @param int $object_id The ID of the current object.
* @param string $cmb_id The current box ID.
*/
public function update_is_configured_value( $object_id, $cmb_id ) {
if ( 0 !== strpos( $cmb_id, 'rank_math' ) && 0 !== strpos( $cmb_id, 'rank-math' ) ) {
return;
}
Helper::is_configured( true );
}
/**
* Deactivate plugin.
*/
public function deactivate_plugins() {
check_ajax_referer( 'rank-math-ajax-nonce', 'security' );
$plugin = Param::post( 'plugin' );
if ( 'all' !== $plugin ) {
deactivate_plugins( $plugin );
die( '1' );
}
Importers\Detector::deactivate_all();
die( '1' );
}
/**
* Get dashbaord navigation links
*
* @return array
*/
private function get_nav_links() {
$links = [
'modules' => [
'url' => '',
'args' => 'view=modules',
'cap' => 'manage_options',
'title' => esc_html__( 'Modules', 'rank-math' ),
],
'help' => [
'url' => '',
'args' => 'view=help',
'cap' => 'manage_options',
'title' => esc_html__( 'Help', 'rank-math' ),
],
'wizard' => [
'url' => 'wizard',
'args' => '',
'cap' => 'manage_options',
'title' => esc_html__( 'Setup Wizard', 'rank-math' ),
],
'import-export' => [
'url' => 'import-export',
'args' => '',
'cap' => 'manage_options',
'title' => esc_html__( 'Import & Export', 'rank-math' ),
],
];
if ( Helper::is_plugin_active_for_network() ) {
unset( $links['help'] );
}
return $links;
}
}