885ecdae by Chris Boden

Added home button to branding; fixed PagePermission issue on Media. fixes #556, fixes #534

1 parent 3e664ea6
......@@ -8,6 +8,8 @@
} else {
echo($current_user->user_login);
}
?></a> | <a href="<?php echo wp_logout_url(); ?>">Log Out</a>
?></a>
| <a href="<?php echo get_settings('siteurl');?>">Home</a>
| <a href="<?php echo _logout_url(); ?>">Log Out</a>
</div>
</div>
\ No newline at end of file
......
......@@ -70,7 +70,7 @@ class PagePermissions {
}
// Meta value hasn't been set, getting settings defaults
if ('' === $data = get_custom_data(self::META, $post_id)) {
if ('' === $data = array_shift(get_post_meta($post_id, self::META))) {
$data = Array(self::ELE_SEL => $settings[self::ELE_SEL], self::ELE_CUST => $settings[self::ELE_CUST]);
}
......@@ -201,7 +201,7 @@ class PagePermissionsAdmin {
}
public static function viewMetaBox($post, $box_info) {
$selected = ($post->ID == 0 ? self::getOptions() : get_custom_data(PagePermissions::META, $post->ID));
$selected = ($post->ID == 0 ? self::getOptions() : array_shift(get_post_meta($post->ID, PagePermissions::META)));
// If the post doesn't have the field saved get defaults
if (empty($selected)) {
......@@ -262,6 +262,27 @@ class PagePermissions_Actions {
if ($file == '/wp-admin/media-new.php' && !PagePermissions::is_admin()) {
header("Location: " . $file . "?flash=0");
}
// This is hackey, but WP does't have hooks for this for some reason...
// Ideally this is in its own `edit_attachment` method...but that isn't working
if (isset($_POST['action']) && $_POST['action'] == 'editattachment') {
$real_id = $_POST['attachment_id'];
$current = array_shift(get_post_meta($real_id, PagePermissions::META));
$new = Array();
$new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL];
if (isset($_POST[PagePermissions::ELE_CUST])) {
$new[PagePermissions::ELE_CUST] = $_POST[PagePermissions::ELE_CUST];
} else {
$new[PagePermissions::ELE_CUST] = Array();
}
if (empty($current)) {
add_post_meta($real_id, PagePermissions::META, $new, true);
} else {
update_post_meta($real_id, PagePermissions::META, $new);
}
}
}
public static function admin_menu() {
......@@ -274,7 +295,7 @@ class PagePermissions_Actions {
public static function admin_print_scripts() {
$innerhtml = '';
if ('0' !== ($change_field = (isset($_GET['attachment_id']) ? 'attachments[' . $_GET['attachment_id'] . '][' . PagePermissions::META . ']' : '0'))) {
$selected = get_custom_data(PagePermissions::META, $_GET['attachment_id']);
$selected = array_shift(get_post_meta($_GET['attachment_id'], PagePermissions::META));
if (empty($selected)) {
$selected = PagePermissionsAdmin::getOptions();
}
......@@ -292,9 +313,6 @@ class PagePermissions_Actions {
, 'change_field' => $change_field
, 'innerHTML' => rawurlencode($innerhtml)
));
//attachments[304][accessible_to_roles]
//a:2:{s:14:"general_access";s:1:"1";s:5:"roles";a:1:{s:6:"editor";s:1:"1";}}
}
public static function save_post($post_id) {
......@@ -305,7 +323,7 @@ class PagePermissions_Actions {
if (false === ($real_id = _is_post_revision($post_id))) {
$real_id = $post_id;
}
$current = get_custom_data(PagePermissions::META, $real_id);
$current = array_shift(get_post_meta($real_id, PagePermissions::META));
$new = Array();
$new[PagePermissions::ELE_SEL] = $_POST[PagePermissions::ELE_SEL];
......
......@@ -74,42 +74,4 @@ function add_filters($class) {
add_filter($method->name, Array($class, $method->name));
}
}
function get_custom_data($name, $post_id = false) {
if (false === $type = get_post_type($post_id)) {
throw new InvalidArgumentException("Post {$post_id} does not exist");
}
$raw_data = call_user_func_array("_custom_{$type}", Array($post_id, $name));
if (null === $raw_data) {
return '';
}
return $raw_data;
}
function _custom_attachment($post_id, $custom_name) {
if (false === ($tax_object = get_the_terms($post_id, $custom_name))) {
return '';
}
$tax_data = array_shift($tax_object);
return $tax_data->name;
}
function _custom_page($post_id, $custom_name) {
$custom = get_post_meta($post_id, $custom_name);
return array_shift($custom);
}
function _custom_post() {
$args = func_get_args();
return call_user_func_array('_custom_page', $args);
}
function _custom_revision() {
$args = func_get_args();
return call_user_func_array('_custom_page', $args);
}
?>
\ No newline at end of file
......
......@@ -154,4 +154,9 @@ function _make_link_relative() {
$params = func_get_args();
return call_user_func_array('wp' . __FUNCTION__, $params);
}
function _logout_url() {
$params = func_get_args();
return call_user_func_array('wp' . __FUNCTION__, $params);
}
?>
......