options = $options;
$this->init();
}
/**
* Start the engine running
*
* @return void
*/
private function init() {
add_filter( 'adminoptimizer_settings_navtab', [ $this, 'add_settings_navtab' ] );
add_filter( 'adminoptimizer_settings_sections', [ $this, 'settings_fields' ] );
if ( ! empty( $this->options['enable_txt_management'] ) ) {
$this->modules['txt'] = new Ads_Robots_Txt();
}
if ( ! empty( $this->options['enable_xml_sitemap'] ) ) {
$this->modules['sitemap'] = new XML_Sitemap();
}
if ( ! empty( $this->options['enable_redirect_manager'] ) ) {
$this->modules['redirect_manager'] = new Redirect_Manager();
}
add_action( 'template_redirect', [ $this, 'disable_frontend_pages' ] );
}
/**
* Add settings navtab
*
* @param array $nav_tab List of nav tabs.
*
* @return array
*/
public function add_settings_navtab( $nav_tab ) {
if ( empty( $nav_tab['seo'] ) ) {
$nav_tab['seo'] = [
'title' => __( 'SEO', 'admin-optimizer' ),
'slug' => 'adminoptim-seo-settings',
];
}
return $nav_tab;
}
/**
* List of Settings fields
*
* @param array $fields Settings fields.
*
* @return array
*/
public function settings_fields( $fields ) {
if ( empty( $fields['seo-module'] ) ) {
$fields['seo-module'] = [
'id' => 'adminoptimizer-seo-module-settings',
'title' => __( 'Modules', 'admin-optimizer' ),
'description' => '',
'menu_slug' => 'adminoptim-seo-settings',
'option_name' => MODULES_OPTION,
'args' => [
'before_section' => '
',
'after_section' => '
',
'section_class' => 'module',
],
'fields' => [
[
'type' => 'slider-checkbox',
'title' => __( 'SEO Manager (Pro only)', 'admin-optimizer' ),
'id' => 'enable-seo-manager',
'name' => 'enable_seo_manager',
'disabled' => 'disabled',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'SEO module to optimize your content (with AI SEO optimization)%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'XML Sitemap on your site (Pro option)', 'admin-optimizer' ),
'id' => 'enable-xml-sitemap',
'name' => 'enable_xml_sitemap',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Enable and manage XML Sitemap for your site. (comes with Pro options)%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'Redirect Manager (Pro option)', 'admin-optimizer' ),
'id' => 'enable-redirect-manager',
'name' => 'enable_redirect_manager',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Enable and manage URL redirection for your site. (comes with Pro options)%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'Robots.txt & Ads.txt manager', 'admin-optimizer' ),
'id' => 'enable-txt-management',
'name' => 'enable_txt_management',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Manage robots.txt, ads.txt, app-ads.txt directly in WordPress.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
],
];
}
if ( empty( $fields['seo-tweaks'] ) ) {
$fields['seo-tweaks'] = [
'id' => 'adminoptimizer-seo-tweaks-settings',
'title' => __( 'Tweaks', 'admin-optimizer' ),
'description' => __( 'Activate with a single click. No additional configuration required.', 'admin-optimizer' ),
'menu_slug' => 'adminoptim-seo-settings',
'option_name' => MODULES_OPTION,
'args' => [
'before_section' => '',
'after_section' => '
',
'section_class' => 'tweaks',
],
'fields' => [
[
'type' => 'slider-checkbox',
'title' => __( 'Disable Category Archive Page (frontend)', 'admin-optimizer' ),
'id' => 'disable-category-archive',
'name' => 'disable_category_archive',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Disable all Category archive pages in the site frontend. Loading the Category archive URL will return a 404 (Not Found) error. This will not remove the Category feature in the Admin dashboard.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'Disable Tag Archive Page (frontend)', 'admin-optimizer' ),
'id' => 'disable-tag-archive',
'name' => 'disable_tag_archive',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Disable all Tag archive pages in the site frontend. Loading the Tag archive URL will return a 404 (Not Found) error. This will not remove the Tag feature in the Admin dashboard.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'Disable Author Archive Page (frontend)', 'admin-optimizer' ),
'id' => 'disable-author-archive',
'name' => 'disable_author_archive',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Disable all Author archive pages in the site frontend. Loading the Author archive URL will return a 404 (Not Found) error. This will not remove the Author feature in the Admin dashboard.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
[
'type' => 'slider-checkbox',
'title' => __( 'Disable Date Archive Page (frontend)', 'admin-optimizer' ),
'id' => 'disable-date-archive',
'name' => 'disable_date_archive',
// translators: %1$s is the line break tag. %2$s is the anchor tag. %3$s is the anchor closure tag.
'label' => sprintf( __( 'Disable all Date archive pages in the site frontend. Loading the Date archive URL will return a 404 (Not Found) error. This will not remove the Date feature in the Admin dashboard.%1$s%2$sLearn more%3$s', 'admin-optimizer' ), '
', '', '' ),
],
],
];
}
return $fields;
}
/**
* Disable Frontend archive pages
*
* @return void
*/
public function disable_frontend_pages() {
if ( ! is_admin() ) {
global $wp_query;
$set_404 = false;
if ( ! empty( $this->options['disable_category_archive'] ) && is_category() ) {
$set_404 = true;
} elseif ( ! empty( $this->options['disable_tag_archive'] ) && is_tag() ) {
$set_404 = true;
} elseif ( ! empty( $this->options['disable_author_archive'] ) && is_author() ) {
$set_404 = true;
} elseif ( ! empty( $this->options['disable_date_archive'] ) && is_date() ) {
$set_404 = true;
}
if ( $set_404 ) {
$wp_query->set_404();
}
}
}
}