tag
__( 'Settings', 'aryo-aal' ), // menu label
'manage_options', // required cap to view this page
$this->slug = 'activity-log-settings', // page slug
array( &$this, 'display_settings_page' ) // callback
);
// this callback will initialize the settings for AAL
// add_action( "load-$this->hook", array( $this, 'register_settings' ) );
}
public function register_settings() {
// If no options exist, create them.
if ( ! get_option( $this->slug ) ) {
update_option( $this->slug, apply_filters( 'aal_default_options', array(
'logs_lifespan' => '30',
) ) );
}
// First, we register a section. This is necessary since all future options must belong to a
add_settings_section(
'general_settings_section', // ID used to identify this section and with which to register options
__( 'Display Options', 'aryo-aal' ), // Title to be displayed on the administration page
array( 'AAL_Settings_Fields', 'description' ), // Callback used to render the description of the section
$this->slug // Page on which to add this section of options
);
add_settings_field(
'logs_lifespan',
__( 'Keep logs for', 'aryo-aal' ),
array( 'AAL_Settings_Fields', 'number_field' ),
$this->slug,
'general_settings_section',
array(
'id' => 'logs_lifespan',
'page' => $this->slug,
'classes' => array( 'small-text' ),
'type' => 'number',
'sub_desc' => __( 'days.', 'aryo-aal' ),
'desc' => __( 'Maximum number of days to keep activity log. Leave blank to keep activity log forever (not recommended).', 'aryo-aal' ),
)
);
add_settings_field(
'raw_delete_log_activities',
__( 'Delete Log Activities', 'aryo-aal' ),
array( 'AAL_Settings_Fields', 'raw_html' ),
$this->slug,
'general_settings_section',
array(
'html' => sprintf( __( 'Reset Database', 'aryo-aal' ), add_query_arg( array(
'action' => 'aal_reset_stream',
'_nonce' => wp_create_nonce( 'aal_reset_stream' ),
), admin_url( 'admin-ajax.php' ) ), 'aal-delete-log-activities' ),
'desc' => __( 'Warning: Clicking this will delete all activities from the database.', 'aryo-aal' ),
)
);
register_setting( 'aal-options', $this->slug );
}
public function display_settings_page() {
?>
%s
', __( 'All activities have been successfully deleted.', 'aryo-aal' ) );
break;
}
}
public function admin_footer() {
// TODO: move to a separate file.
?>
'activity-log-settings',
'message' => 'data_erased',
), admin_url( 'admin.php' ) ) );
die();
}
public static function get_option( $key = '' ) {
$settings = get_option( 'activity-log-settings' );
return ! empty( $settings[ $key ] ) ? $settings[ $key ] : false;
}
}
// TODO: Need rewrite this class to useful tool.
final class AAL_Settings_Fields {
public static function description() {
?>
array(),
) );
if ( empty( $args['id'] ) || empty( $args['page'] ) )
return;
?>
array(),
'min' => '1',
'step' => '1',
'desc' => '',
) );
if ( empty( $args['id'] ) || empty( $args['page'] ) )
return;
?>