-
Notifications
You must be signed in to change notification settings - Fork 14
Admin Cook Book
Alexander Teshabaev edited this page Dec 29, 2019
·
1 revision
You may use anycomment/admin/tabs
filter to add new tab into the list.
Here is an example taken from AnyComment Analytics plugin:
add_filter('anycomment/admin/tabs', function ($tabs, $active_tab) {
$tabs['analytics'] = [
'url' => menu_page_url($_GET['page'], false) . '&tab=analytics',
'text' => __('Analytics', 'anycomment-analytics'),
'callback' => ANYCOMMENT_ANALYTICS_ABSPATH . '/templates/graphs',
];
return $tabs;
}, 11, 2);
Tour allows you to add guide steps for showing certain parts on the page. It is useful as introduction guide.
AnyComment is using Intro.js for this.
You may use anycomment/admin/tour-steps
filter to add new rules for the tour on certain pages or apply changes to existing list.
add_filter('anycomment/admin/tour-steps', function ($steps) {
$steps['some-tab-name'][] = [
'element' => '#some-id', //alternatively you can use class name
'intro' => 'Some text to be displayed at this step',
];
return $steps;
}, 11, 1);
AnyComment is using Woption microframework to manage options.
You can read more about it in their Wiki page.
If you would like to add your own settings you use AnyCommentOptionManager
class:
Here is an example:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
use AnyComment\Options\AnyCommentOptionManager;
class MySettings extends AnyCommentOptionManager {
const REPORT_EMAIL_RECIPIENTS = 'report_email_to';
const REPORT_PERIOD = 'report_period';
const REPORT_PERIOD_DAILY = 'daily';
const REPORT_PERIOD_WEEKLY = 'weekly';
const REPORT_PERIOD_MONTHLY = 'monthly';
/**
* @inheritdoc
*/
protected $option_group = 'anycomment-analytics-report-group';
/**
* @inheritdoc
*/
protected $option_name = 'anycomment-analytics-report';
/**
* @inheritdoc
*/
protected $field_options = [
'wrapper' => '<div class="cell anycomment-form-wrapper__field">{content}</div>',
];
/**
* @inheritdoc
*/
protected $section_options = [
'wrapper' => '<div class="grid-x anycomment-form-wrapper anycomment-tabs__container__tab" id="{id}">{content}</div>',
];
/**
* AnyCommentAdminPages constructor.
*
* @param bool $init if required to init the modle.
*/
public function __construct ( $init = true ) {
parent::__construct();
if ( $init ) {
$this->init_settings();
}
}
/**
* {@inheritdoc}
*/
public function init_settings () {
$form = $this->form();
$form->add_section(
$this->section_builder()
->set_id( 'report' )
->set_title( __( 'Report', "anycomment-analytics" ) )
->set_wrapper( '<div class="grid-x anycomment-form-wrapper anycomment-tabs__container__tab current" id="{id}">{content}</div>' )
->set_fields( [
$this->field_builder()
->text()
->set_id( self::REPORT_EMAIL_RECIPIENTS )
->set_title( __( 'Email recipients', 'anycomment-analytics' ) )
->set_description( sprintf( __( 'By default we send report to "Email Address" listed in "<a href="%s">General</a>" settings. You may specify different email or list of them separated by comma. e.g. "[email protected],[email protected]" to send email to two recipients.', "anycomment-analytics" ), '/wp-admin/options-general.php' ) ),
$this->field_builder()
->set_id( self::REPORT_PERIOD )
->select()
->set_title( __( 'Report period', "anycomment-analytics" ) )
->set_args( [
'options' => [
self::REPORT_PERIOD_DAILY => __( 'Daily', 'anycomment-analytics' ),
self::REPORT_PERIOD_WEEKLY => __( 'Weekly', 'anycomment-analytics' ),
self::REPORT_PERIOD_MONTHLY => __( 'Monthly', 'anycomment-analytics' ),
],
] )
->set_description( esc_html( __( 'Report interval. Define what is good period to receive a report.', "anycomment-analytics" ) ) ),
] )
);
}
}
You can see complete example here.