Skip to content

Commit

Permalink
make plugin compatible with Kirby 2.2
Browse files Browse the repository at this point in the history
This version of the plugin is only compatible with Kirby 2.2, to use it with Kirby 2.1 use the previous version (1.1)
  • Loading branch information
groenewege committed Nov 19, 2015
1 parent e2d1c42 commit fc29343
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion PLUGIN_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

By default, new pages are invisible on creation. This plugin allows you to make all new pages or certain types of pages visible by default.

**Requires** : Kirby 2.1
version 1.* : **Requires** : Kirby 2.1
version 2.* : **Requires** : Kirby 2.2

## Installation

Expand Down
11 changes: 10 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Kirby Auto Publish

This plugin extends [Kirby 2.1](http://getkirby.com) with the possibility to auto publish pages that are created with the Kirby Admin Panel.
This plugin extends [Kirby](http://getkirby.com) with the possibility to auto publish pages that are created with the Kirby Admin Panel.

By default new pages are invisible on creation. This plugin allows you to make all new pages or certain types of pages visible by default.

## Version compatibility

- version 1.* is compatible with Kirby 2.1
- version 2.* is compatible with Kirby 2.2

## Installation

Copy the `site/plugins/autopublish` directory to your `site/plugins/` directory.
Expand All @@ -20,6 +25,10 @@ i.e. if you wish to make all pages using the "project" and "item" template visib
c::set('autopublish.templates', array('project', 'item'));
```

## Known issues

The plugin can conflict with other code or plugins that use the `panel.page.create` hook.

---

This plugin is brought to you by [Kirby Project Hub](https://www.project-hub.net)
15 changes: 6 additions & 9 deletions site/plugins/autopublish/autopublish.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php

kirby()->hook('panel.page.create', function($page) {
$templates = c::get('autopublish.templates', false);
kirby()->hook('panel.page.create', 'run');

function run( $page ) {
$templates = c::get('autopublish.templates', array('project', 'item'));
if (!$templates || in_array($page->template(), $templates)) {
$parent = $page->parent();
$subpages = new Subpages($parent);
try {
$num = $subpages->sort($page, 'last');
return response::success('The page has been sorted', array(
'num' => $num
));
$page->toggle('last');
} catch(Exception $e) {
return response::error($e->getMessage());
}
}
});
}

0 comments on commit fc29343

Please sign in to comment.