Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrommen committed Jul 16, 2017
0 parents commit cc18368
Show file tree
Hide file tree
Showing 12 changed files with 341 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
indent_style = tab
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 120

[{*.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* text eol=lf
*.gif binary

/.github export-ignore
/assets export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
31 changes: 31 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Thanks for contributing—you rock!

# Getting Started

* Make sure you have a [GitHub account](https://github.com/signup/free).
* See if your issue has been discussed (or even fixed) earlier. You can [search for existing issues](../../../issues?q=is%3Aissue).
* Assuming it does not already exist, [create a new issue](../../../issues/new).
* Clearly describe the issue. In case you want to report a bug, include steps to reproduce it.
* Make sure you fill in the earliest version that you know has the issue.
* Fork the repository on GitHub.

# Making Changes

* Create a topic branch from where you want to base your work.
* This is usually the `master` branch.
* Only target release branches if you are certain your fix must be on that branch.
* To quickly create a topic branch based on the `master` branch:
* `git checkout -b issue/%YOUR-ISSUE-NUMBER%_%DESCRIPTIVE-TITLE% master`
* a good example is `issue/123_typo_in_readme`
* Make commits of logical units.
* Make sure your commit messages are helpful.

# Submitting Changes

* Push your changes to the according topic branch in your fork of the repository.
* [Create a pull request](../../../compare) to our repository.
* Wait for feedback. The team looks at pull requests on a regular basis.

# License

By contributing code, you grant its use under the [MIT License](../LICENSE).
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
Thanks for contributing&mdash;you rock!
Please note:
- These comments won't show up when you submit the issue.
- Please choose a descriptive title (e.g., "Typo in readme").
- Almost everything is optional, but please try to provide as many details as possible.
- If requesting a new feature, please explain why you'd like to see it added.
-->

#### Version Information

* PHP:
* WordPress:

#### Steps to Reproduce

1.
1.
1.

#### What I Expected



#### What Happened Instead

19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
Thanks for contributing&mdash;you rock!
Please note:
- These comments won't show up when you submit the pull request.
- Please make sure your changes respect the WordPress Coding Standards:
- https://make.wordpress.org/core/handbook/best-practices/coding-standards/
- In case you introduced a new action or filter hook, please also include inline documentation:
- https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/
- Please create tests, if you can.
-->

This pull request fixes issue #.

#### What's Included in This Pull Request

*
*
*
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Backups
*~
*.DS_Store
*.out
*.so
*.swp

# Logs
logs
*.log

# Composer
composer.lock
vendor

# Node
.npm
node_modules
npm-debug.log*

# PhpStorm
.idea

# PHPUnit
phpunit.xml


# Git
!.gitkeep
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

-

### Changed

-

### Fixed

-

### Removed

-

## [1.0.0] - 2017-07-16

Initial release.

----

[Unreleased]: https://github.com/tfrommen/Dobby/compare/v1.0.0...HEAD
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Thorsten Frommen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Dobby

[![Version](https://img.shields.io/packagist/v/tfrommen/dobby.svg)](https://packagist.org/packages/tfrommen/dobby)
[![Status](https://img.shields.io/badge/status-active-brightgreen.svg)](https://github.com/tfrommen/Dobby)
[![Downloads](https://img.shields.io/packagist/dt/tfrommen/dobby.svg)](https://packagist.org/packages/tfrommen/dobby)
[![License](https://img.shields.io/packagist/l/tfrommen/dobby.svg)](https://packagist.org/packages/tfrommen/dobby)

> Dobby, the friendly Admin Elf, takes care of all your (unwanted) admin notices.
## Installation

Install with [Composer](https://getcomposer.org):

```sh
$ composer require tfrommen/dobby
```

Or:

1. [Download ZIP](https://github.com/tfrommen/Dobby/releases).
1. Upload contents to the `/wp-content/plugins/` directory on your web server.
1. Activate the plugin through the _Plugins_ menu in WordPress.
1. See only a single admin notice, if at all.

### Requirements

This plugin **requires PHP 5.4** or higher, but you really **should be using PHP 7** or higher, as we all know.

## Usage

Dobby captured everything that gets printed on one of the admin notice hooks (i.e., `network_admin_notices`, `user_admin_notices`, `admin_notices` and `all_admin_notices`), and hides it, for now.
In case Dobby captured anything, he will inform you (yes, via an admin notice).

![Dobby in Action](assets/images/dobby.gif)

## License

Copyright (c) 2017 Thorsten Frommen

This code is licensed under the [MIT License](LICENSE).
Binary file added assets/images/dobby.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "tfrommen/dobby",
"description": "Dobby, the friendly Admin Elf, takes care of all your (unwanted) admin notices.",
"type": "wordpress-plugin",
"keywords": [
"admin",
"dobby",
"notices"
],
"license": "MIT",
"authors": [
{
"name": "Thorsten Frommen",
"email": "info@tfrommen.de",
"homepage": "https://twitter.com/thorstenfrommen",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/tfrommen/Dobby/issues",
"source": "https://github.com/tfrommen/Dobby"
},
"require": {
"php": ">=5.4"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
}
87 changes: 87 additions & 0 deletions dobby.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php # -*- coding: utf-8 -*-
/*
* Plugin Name: Dobby
* Plugin URI: https://github.com/tfrommen/Dobby/
* Description: Dobby, the friendly Admin Elf, takes care of all your (unwanted) admin notices.
* Author: Thorsten Frommen
* Author URI: https://tfrommen.de
* Version: 1.0.0
* License: MIT
*/

namespace tfrommen\Dobby;

defined( 'ABSPATH' ) or die();

if ( ! is_admin() ) {
return;
}

/**
* Bootstraps the plugin.
*
* @wp-hook plugins_loaded
*
* @return void
*/
function bootstrap() {

if ( is_network_admin() ) {
$action = 'network_admin_notices';
} elseif ( is_user_admin() ) {
$action = 'user_admin_notices';
} else {
$action = 'admin_notices';
}
add_action( $action, function () {

ob_start();
}, PHP_INT_MAX + 1 );

add_action( 'all_admin_notices', function () {

load_plugin_textdomain( 'dobby' );

$contents = trim( ob_get_clean() );
if ( ! $contents ) {
return;
}

$contents = preg_replace(
'/(\sclass=["\'][^"\']*?notice)(["\'\s])/',
'$1 inline$2',
$contents
);

$button = '<button class="button dobby-button">' . __( 'Toggle notices', 'dobby' ) . '</button>';

/** translators: s: <button> tagto display admin notices */
$message = __( 'Dobby took care of your admin notices. %s', 'dobby' );

printf(
'<div id="dobby" class="notice notice-info"><p>%s</p></div><div class="dobby-notices hide-if-js">%s</div>',
sprintf( $message, $button ),
$contents
);

add_action( 'admin_footer', function () {

$js = <<<JS
jQuery( function () {
var notices;
jQuery( '#wpbody-content' ).on( 'click', '.dobby-button', function () {
if ( ! notices ) {
notices = jQuery( '.dobby-notices' );
notices.insertAfter( '#dobby' );
}
notices.toggle();
} );
} );
JS;
echo "<script>{$js}</script>";
} );
}, PHP_INT_MAX );
}

add_action( 'plugins_loaded', __NAMESPACE__ . '\\bootstrap' );

0 comments on commit cc18368

Please sign in to comment.