Skip to content

Commit 288c3c4

Browse files
author
Martijn Russchen
committed
Merge pull request #17 from Factlink/change-admin-page-options-layout
Change admin page options layout
2 parents 910cbb5 + 83177ba commit 288c3c4

7 files changed

Lines changed: 72 additions & 79 deletions

File tree

trunk/app/capability/admin_page.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ public function initialize()
2626
// register the options that can be updated through the view
2727
// needs to be called, otherwise the settings won't register and a strange page will be displayed
2828
$this->settings->enabled_for_pages->register();
29-
$this->settings->enabled_for_all_pages->register();
30-
3129
$this->settings->enabled_for_posts->register();
32-
$this->settings->enabled_for_all_posts->register();
33-
3430
$this->settings->disable_global_comments->register();
3531
}
3632

trunk/app/capability/include_factlink.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,8 @@ public function initialize()
1414
{
1515
$id = get_queried_object_id();
1616

17-
if ($this->settings->enabled_for_pages->get() == 1 &&
18-
19-
is_page() &&
20-
21-
($this->settings->enabled_for_all_pages->get() == 0 && $this->settings->page_meta->get($id) == 1) ||
22-
23-
$this->settings->enabled_for_all_pages->get() == 1
24-
25-
) {
26-
$this->render();
27-
}
28-
29-
if ($this->settings->enabled_for_posts->get() == 1 &&
30-
31-
is_single() &&
32-
33-
($this->settings->enabled_for_all_posts->get() == 0 && $this->settings->post_meta->get($id) == 1) ||
34-
35-
$this->settings->enabled_for_all_posts->get() == 1
36-
) {
37-
// render factlink
17+
if ($this->settings->is_enabled_for_post($id))
18+
{
3819
$this->render();
3920
}
4021
}

trunk/app/capability/meta_box.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class MetaBox extends \vg\wordpress_plugin\capability\Capability
1313
public $meta_name;
1414
public $meta_value;
1515

16+
public $is_published;
17+
1618
public function initialize($post_type, $post)
1719
{
1820
$this->meta_name = $this->settings->post_meta->name;
@@ -22,18 +24,16 @@ public function initialize($post_type, $post)
2224
$title = 'FactLink settings';
2325
$context = 'advanced';
2426

25-
if (
26-
$this->settings->enabled_for_pages->get() == 1 &&
27-
$post_type == 'page' &&
28-
$this->settings->enabled_for_all_pages->get() == 0
29-
) {
27+
// get the post status of the current post
28+
$this->is_published = get_post_status(get_queried_object_id()) == 'publish';
29+
30+
if ($this->settings->enabled_for_pages->get() == 1 && $post_type == 'page')
31+
{
3032
add_meta_box($id, $title, array($this, 'render_page_meta_box'), 'page', $context);
3133
}
3234

33-
if ($this->settings->enabled_for_posts->get() == 1 &&
34-
$post_type == 'post' &&
35-
$this->settings->enabled_for_all_posts->get() == 0
36-
) {
35+
if ($this->settings->enabled_for_posts->get() == 1 && $post_type == 'post')
36+
{
3737
add_meta_box($id, $title, array($this, 'render_post_meta_box'), 'post', $context);
3838
}
3939
}

trunk/app/model/settings.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
class Settings extends \vg\wordpress_plugin\model\Model
66
{
77
public $enabled_for_posts;
8-
public $enabled_for_all_posts;
9-
108
public $enabled_for_pages;
11-
public $enabled_for_all_pages;
129

1310
public $is_configured;
1411
public $disable_global_comments;
@@ -29,16 +26,10 @@ function initialize()
2926
$this->menu_url = get_admin_url(null, $this->menu_parent_slug . "?page=" . $this->menu_slug);
3027

3128
// setting if factlink is enabled for all the posts
32-
$this->enabled_for_posts = $this->create_option_meta('enabled_for_posts', 'global_settings', 1, array('int'));
33-
34-
// setting to determine if default factlink is enabled for a post or default is disabled
35-
$this->enabled_for_all_posts = $this->create_option_meta('enabled_for_all_posts', 'global_settings', 1, array('int'));
29+
$this->enabled_for_posts = $this->create_option_meta('enabled_for_posts', 'global_settings', 2, array('int'));
3630

3731
// setting if factlink is enabled for all the pages
38-
$this->enabled_for_pages = $this->create_option_meta('enabled_for_pages', 'global_settings', 1, array('int'));
39-
40-
// setting to determine if default factlink is enabled for a page or default is disabled
41-
$this->enabled_for_all_pages = $this->create_option_meta('enabled_for_all_pages', 'global_settings', 1, array('int'));
32+
$this->enabled_for_pages = $this->create_option_meta('enabled_for_pages', 'global_settings', 2, array('int'));
4233

4334
// setting to display configuration message as long factlink isn't configured
4435
$this->is_configured = $this->create_option_meta('is_configured', 'global_settings', 0, array('int'));
@@ -59,4 +50,32 @@ public function activate()
5950
// set the state of the is_configured to 0 -> not configured
6051
$this->is_configured->set(0);
6152
}
53+
54+
public function is_enabled_for_post($post_id)
55+
{
56+
// 1 means only selected posts
57+
if ($this->enabled_for_pages->get() == 1 && $this->page_meta->get($post_id) == 1 && is_page())
58+
{
59+
return true;
60+
}
61+
62+
// 2 means enabled for all pages
63+
if ($this->enabled_for_pages->get() == 2 && is_page())
64+
{
65+
return true;
66+
}
67+
68+
// is_single means if the current page is a single post
69+
if ($this->enabled_for_posts->get() == 1 && $this->post_meta->get($post_id) == 1 && is_single())
70+
{
71+
return true;
72+
}
73+
74+
if ($this->enabled_for_posts->get() == 2 && is_single())
75+
{
76+
return true;
77+
}
78+
79+
return false;
80+
}
6281
}

trunk/app/view/admin_page.php

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,71 +18,68 @@
1818
<table class="form-table">
1919

2020
<tr>
21-
<th scope="row">Posts</th>
21+
<th scope="row">Enable discussions on posts:</th>
2222
<td>
2323
<fieldset>
24-
<input type="hidden" name="<?php echo $this->settings->enabled_for_posts->name(); ?>" value="0">
25-
<input type="checkbox"
26-
name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
27-
id="<?php echo $this->settings->enabled_for_posts->name(); ?>"
28-
value="1"
29-
<?php if ($this->settings->enabled_for_posts->get() == 1) {
30-
echo 'checked';
31-
} ?>>
32-
<label for="<?php echo $this->settings->enabled_for_posts->name(); ?>">Enabled for posts</label>
3324

34-
<br/>
3525
<label>
36-
<input type="radio" name="<?php echo $this->settings->enabled_for_all_posts->name(); ?>"
37-
value="1" <?php if ($this->settings->enabled_for_all_posts->get() == "1") {
26+
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
27+
value="2" <?php if ($this->settings->enabled_for_posts->get() == "2") {
3828
echo "checked";
3929
} ?>>
4030
All posts
4131
</label>
4232
<br/>
4333

4434
<label>
45-
<input type="radio" name="<?php echo $this->settings->enabled_for_all_posts->name(); ?>"
46-
value="0" <?php if ($this->settings->enabled_for_all_posts->get() == "0") {
35+
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
36+
value="1" <?php if ($this->settings->enabled_for_posts->get() == "1") {
4737
echo "checked";
4838
} ?>>
4939
Selected posts
5040
</label>
41+
<br/>
42+
43+
<label>
44+
<input type="radio" name="<?php echo $this->settings->enabled_for_posts->name(); ?>"
45+
value="0" <?php if ($this->settings->enabled_for_posts->get() == "0") {
46+
echo "checked";
47+
} ?>>
48+
No posts
49+
</label>
5150
</fieldset>
5251
</td>
5352
</tr>
5453

5554
<tr>
56-
<th scope="row">Pages</th>
55+
<th scope="row">Enable discussions on pages:</th>
5756
<td>
5857
<fieldset>
59-
<input type="hidden" name="<?php echo $this->settings->enabled_for_pages->name(); ?>" value="0">
60-
<input type="checkbox"
61-
name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
62-
id="<?php echo $this->settings->enabled_for_pages->name(); ?>"
63-
value="1"
64-
<?php if ($this->settings->enabled_for_pages->get() == 1) {
65-
echo 'checked';
66-
} ?>>
67-
<label for="<?php echo $this->settings->enabled_for_pages->name(); ?>">Enabled for pages</label>
68-
69-
<br/>
7058
<label>
71-
<input type="radio" name="<?php echo $this->settings->enabled_for_all_pages->name(); ?>"
72-
value="1" <?php if ($this->settings->enabled_for_all_pages->get() == "1") {
59+
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
60+
value="2" <?php if ($this->settings->enabled_for_pages->get() == "2") {
7361
echo "checked";
7462
} ?>>
7563
All pages
7664
</label>
7765
<br/>
7866

7967
<label>
80-
<input type="radio" name="<?php echo $this->settings->enabled_for_all_pages->name(); ?>"
81-
value="0" <?php if ($this->settings->enabled_for_all_pages->get() == "0") {
68+
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
69+
value="1" <?php if ($this->settings->enabled_for_pages->get() == "1") {
8270
echo "checked";
8371
} ?>>
8472
Selected pages
8573
</label>
74+
<br/>
75+
76+
<label>
77+
<input type="radio" name="<?php echo $this->settings->enabled_for_pages->name(); ?>"
78+
value="0" <?php if ($this->settings->enabled_for_pages->get() == "0") {
79+
echo "checked";
80+
} ?>>
81+
No pages
82+
</label>
8683
</fieldset>
8784
</td>
8885
</tr>
@@ -99,8 +96,7 @@
9996
} ?> id="<?php echo $this->settings->disable_global_comments->name(); ?>" value="1">
10097
<label for="<?php echo $this->settings->disable_global_comments->name(); ?>">Disable the default Wordpress comments.</label>
10198
</fieldset>
102-
<p class="description">Note: Disables the Wordpress ability to add new comments, but doesn't remove the
103-
existing ones.</p>
99+
<p class="description">Note: Disables the Wordpress ability to add new comments, but still shows the existing ones.</p>
104100
</td>
105101
</tr>
106102

trunk/app/view/meta_box.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<input type="hidden" name="<?php echo $this->meta_name; ?>" value="0">
22
<input type="checkbox" name="<?php echo $this->meta_name; ?>" value="1"
3-
id="<?php echo $this->meta_name; ?>" <?php if ($this->meta_value == 1) {
3+
id="<?php echo $this->meta_name; ?>" <?php if ($this->meta_value == 1 || !$this->is_published) {
44
echo 'checked';
55
} ?>>
66
<label for="<?php echo $this->meta_name; ?>">Enable Factlink for this item</label>

trunk/lib/model/meta/meta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct($name, $default_value, $validators, $model)
1717
$this->default_value = $default_value;
1818
$this->validators = $validators;
1919
$this->model = $model;
20+
$this->prefix = $this->model->meta_prefix;
2021
}
2122

2223
public function get()

0 commit comments

Comments
 (0)