';
break;
default:
@@ -601,9 +606,11 @@ static function get_notices() {
if ( $valid_user_count == 0 ) {
$manage_users_url = admin_url( 'users.php' );
- $users_link = sprintf( '%s', $manage_users_url, __( 'users page', BUSE_TEXTDOMAIN ) );
- $no_users_warning = __( 'There are currently no users on your site that are capable of being assigned to section editing groups.', BUSE_TEXTDOMAIN );
- $role_notice = sprintf( __( 'To start using this plugin, visit the %s and change the role for any users you would like to add to a section editing group to "Section Editor".', BUSE_TEXTDOMAIN ), $users_link );
+ // translators: %s stands for the manage users url.
+ $users_link = sprintf( '%s', $manage_users_url, __( 'users page', 'bu-section-editing' ) );
+ $no_users_warning = __( 'There are currently no users on your site that are capable of being assigned to section editing groups.', 'bu-section-editing' );
+ // translators: %s stands for the manage users url.
+ $role_notice = sprintf( __( 'To start using this plugin, visit the %s and change the role for any users you would like to add to a section editing group to "Section Editor".', 'bu-section-editing' ), $users_link );
$notices['error'][] = "
$no_users_warning
$role_notice
";
}
@@ -693,10 +700,7 @@ static function load_manage_groups() {
// Redirect if we have one
if ( $redirect_url ) {
-
- // Use safe redirect as the redirect URL built with manage_groups_url() begins
- // with admin_url and the final URL should be local.
- wp_safe_redirect( $redirect_url );
+ wp_redirect( $redirect_url );
die();
}
@@ -706,7 +710,7 @@ static function load_manage_groups() {
$group = $groups->get( $group_id );
if ( empty( $group ) ) {
- wp_die( 'No section editing group exists with an ID of : ' . $group_id );
+ wp_die( 'No section editing group exists with an ID of : ' . esc_html( $group_id ) );
}
}
@@ -717,7 +721,7 @@ static function load_manage_groups() {
if ( self::NEW_GROUP_SLUG == $_GET['page'] || $group_id > 0 ) {
add_screen_option( 'per_page', array(
- 'label' => __( 'Posts per page', BUSE_TEXTDOMAIN ),
+ 'label' => __( 'Posts per page', 'bu-section-editing' ),
'default' => 10,
'option' => self::POSTS_PER_PAGE_OPTION,
)
@@ -796,7 +800,7 @@ static function manage_groups_screen() {
if ( $group_id > 0 ) {
$group = $groups->get( $group_id );
- $page_title = __( 'Edit Section Group', BUSE_TEXTDOMAIN );
+ $page_title = __( 'Edit Section Group', 'bu-section-editing' );
$template_path = 'interface/edit-group.php';
} else {
@@ -810,7 +814,7 @@ static function manage_groups_screen() {
// New group page
case self::NEW_GROUP_SLUG:
$group = new BU_Edit_Group();
- $page_title = __( 'Add Section Group', BUSE_TEXTDOMAIN );
+ $page_title = __( 'Add Section Group', 'bu-section-editing' );
$template_path = 'interface/edit-group.php';
break;
}
@@ -917,7 +921,7 @@ static function group_permissions_string( $group, $args = array() ) {
$counts[] = sprintf( '%s%s%s',
$pt->name,
$global_edit,
- __('All', BUSE_TEXTDOMAIN),
+ __('All', 'bu-section-editing'),
$count,
$label
);
diff --git a/bu-section-editing.php b/bu-section-editing.php
index d883df7..4da4d2c 100644
--- a/bu-section-editing.php
+++ b/bu-section-editing.php
@@ -8,6 +8,8 @@
Version: 0.10.0
Text Domain: bu-section-editing
Domain Path: /languages
+License: GPLv2 or later
+License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
/**
@@ -73,7 +75,7 @@ public static function register_hooks() {
public static function l10n() {
- load_plugin_textdomain( BUSE_TEXTDOMAIN, false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );
+ load_plugin_textdomain( 'bu-section-editing', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );
}
@@ -112,17 +114,19 @@ public static function on_activate() {
$msg = '';
if ( ! class_exists( 'BU_Navigation_Plugin' ) ) {
- $install_link = sprintf( '%s', BUSE_NAV_INSTALL_LINK, __( 'BU Navigation plugin', BUSE_TEXTDOMAIN ) );
- $msg = '
' . __( 'The BU Section Editing plugin relies on the BU Navigation plugin for displaying hierarchical permission editors.', BUSE_TEXTDOMAIN ) . '
' . __( 'The BU Section Editing plugin relies on the BU Navigation plugin for displaying hierarchical permission editors.', 'bu-section-editing' ) . '
';
$msg .= '
' . sprintf(
- __( 'Please install and activate the %s in order to set permissions for hierarchical post types.', BUSE_TEXTDOMAIN ),
+ // translators: %s stands for the BU Navigation install link.
+ __( 'Please install and activate the %s in order to set permissions for hierarchical post types.', 'bu-section-editing' ),
$install_link ) . '
';
} else if ( version_compare( BU_Navigation_Plugin::VERSION, '1.1', '<' ) ) {
- $upgrade_link = sprintf( '%s', BUSE_NAV_UPGRADE_LINK, __( 'upgrade your copy of BU Navigation', BUSE_TEXTDOMAIN ) );
- $msg = '
' . __( 'The BU Section Editing plugin relies on the BU Navigation plugin for displaying hierarchical permission editors.', BUSE_TEXTDOMAIN ) . '
';
- $msg .= '
' . __( 'This version of BU Section Editing requires at least version 1.1 of BU Navigation.', BUSE_TEXTDOMAIN ) . '
';
+ $upgrade_link = sprintf( '%s', BUSE_NAV_UPGRADE_LINK, __( 'upgrade your copy of BU Navigation', 'bu-section-editing' ) );
+ $msg = '
' . __( 'The BU Section Editing plugin relies on the BU Navigation plugin for displaying hierarchical permission editors.', 'bu-section-editing' ) . '
';
+ $msg .= '
' . __( 'This version of BU Section Editing requires at least version 1.1 of BU Navigation.', 'bu-section-editing' ) . '
';
$msg .= '
' . sprintf(
- __( 'Please %s to enable permissions for hierarchical post types.', BUSE_TEXTDOMAIN ),
+ // translators: %s stands for the BU Navigation upgrade link.
+ __( 'Please %s to enable permissions for hierarchical post types.', 'bu-section-editing' ),
$upgrade_link ) . '
';
}
@@ -149,7 +153,7 @@ public static function plugin_dependency_nag() {
$notice = get_transient( 'buse_nav_dep_nag' );
if ( $notice ) {
- echo "
$notice
\n";
+ echo esc_html("
$notice
\n", 'bu-section-editing');
delete_transient( 'buse_nav_dep_nag' );
}
@@ -173,7 +177,7 @@ public static function plugin_settings_link( $links, $file ) {
}
$groups_url = admin_url( BU_Groups_Admin::MANAGE_GROUPS_PAGE );
- array_unshift( $links, "" . __( 'Manage Groups', BUSE_TEXTDOMAIN ) . '' );
+ array_unshift( $links, "" . __( 'Manage Groups', 'bu-section-editing' ) . '' );
return $links;
}
diff --git a/classes.groups.php b/classes.groups.php
index bf3a545..ccd3fea 100644
--- a/classes.groups.php
+++ b/classes.groups.php
@@ -51,8 +51,8 @@ static public function register_hooks() {
static public function register_post_type() {
$labels = array(
- 'name' => _x( 'Section Groups', 'Post Type General Name', BUSE_TEXTDOMAIN ),
- 'singular_name' => _x( 'Section Group', 'Post Type Singular Name', BUSE_TEXTDOMAIN ),
+ 'name' => _x( 'Section Groups', 'Post Type General Name', 'bu-section-editing' ),
+ 'singular_name' => _x( 'Section Group', 'Post Type Singular Name', 'bu-section-editing' ),
);
$args = array(
@@ -68,7 +68,7 @@ static public function register_post_type() {
'menu_icon' => '',
'can_export' => true,
'has_archive' => false,
- 'exclude_from_search' => true,
+ 'exclude_from_search' => false,
'publicly_queryable' => false,
'rewrite' => false,
'capability_type' => 'post',
@@ -309,105 +309,111 @@ public function has_user( $groups, $user_id ) {
*
* @return array post ids for the given post type, group or user
*/
- public function get_allowed_posts( $args = array() ) {
- global $wpdb, $bu_navigation_plugin;
-
- $defaults = array(
- 'user_id' => null,
- 'group' => null,
- 'post_type' => null,
- 'include_unpublished' => false,
- 'include_links' => true,
- );
+ /**
+ * Get allowed post ids, optionally filtered by user ID, group or post_type
+ *
+ * @param $args array optional args
+ * @return array post ids for the given post type, group or user
+ */
+ public function get_allowed_posts( $args = array() ) {
+ global $wpdb, $bu_navigation_plugin;
- extract( wp_parse_args( $args, $defaults ) );
+ $defaults = array(
+ 'user_id' => null,
+ 'group' => null,
+ 'post_type' => null,
+ 'include_unpublished' => false,
+ 'include_links' => true,
+ );
- $group_ids = array();
+ extract( wp_parse_args( $args, $defaults ) );
- // If user_id is passed, populate group ID's from their memberships
- if ( $user_id ) {
+ $group_ids = array();
- if ( is_null( get_userdata( $user_id ) ) ) {
- error_log( 'No user found for ID: ' . $user_id );
- return array();
- }
+ // If user_id is passed, populate group ID's from their memberships
+ if ( $user_id ) {
- // Get groups for users
- $group_ids = $this->find_groups_for_user( $user_id, 'ids' );
+ if ( is_null( get_userdata( $user_id ) ) ) {
+ error_log( 'No user found for ID: ' . $user_id );
+ return array();
+ }
- }
+ // Get groups for users
+ $group_ids = $this->find_groups_for_user( $user_id, 'ids' );
- // If no user ID is passed, but a group is, convert to array
- if ( is_null( $user_id ) && $group ) {
+ }
- if ( is_array( $group ) ) {
- $group_ids = $group;
- }
+ // If no user ID is passed, but a group is, convert to array
+ if ( is_null( $user_id ) && $group ) {
- if ( is_numeric( $group ) && $group > 0 ) {
- $group_ids = array( $group );
- }
- }
+ if ( is_array( $group ) ) {
+ $group_ids = $group;
+ }
- // Bail if we don't have any valid groups by now
- if ( empty( $group_ids ) ) {
- return array();
- }
+ if ( is_numeric( $group ) && $group > 0 ) {
+ $group_ids = array( $group );
+ }
+ }
- // Generate query
- $post_type_clause = $post_status_clause = '';
+ // Bail if we don't have any valid groups by now
+ if ( empty( $group_ids ) ) {
+ return array();
+ }
- // Maybe filter by post type and status
- if ( ! is_null( $post_type ) && ! is_null( $pto = get_post_type_object( $post_type ) ) ) {
+ // Generate query
+ $post_type_clause = $post_status_clause = '';
- // Only a single post type is expected, so it should be prepared as a string.
- $post_type_clause = $wpdb->prepare( "AND post_type = %s", $post_type );
+ // Maybe filter by post type and status
+ if ( ! is_null( $post_type ) && ! is_null( $pto = get_post_type_object( $post_type ) ) ) {
- if ( $include_links && $post_type == 'page' && isset( $bu_navigation_plugin ) ) {
- if ( $bu_navigation_plugin->supports( 'links' ) ) {
- $link_post_type = defined( 'BU_NAVIGATION_LINK_POST_TYPE' ) ? BU_NAVIGATION_LINK_POST_TYPE : 'bu_link';
+ $post_type_clause = "AND post_type = '" . esc_sql( $post_type ) . "' ";
- // Only a single post type string is passed, so it can be prepared as normal.
- $post_type_clause = $wpdb->prepare( "AND post_type IN ('page', %s) ", $link_post_type );
- }
- }
- }
+ if ( $include_links && $post_type == 'page' && isset( $bu_navigation_plugin ) ) {
+ if ( $bu_navigation_plugin->supports( 'links' ) ) {
+ $link_post_type = defined( 'BU_NAVIGATION_LINK_POST_TYPE' ) ? BU_NAVIGATION_LINK_POST_TYPE : 'bu_link';
+ $post_type_clause = "AND post_type IN ('page','" . esc_sql( $link_post_type ) . "') ";
+ }
+ }
+ }
- // Include unpublished should only work for hierarchical post types
- if ( $include_unpublished ) {
+ // Include unpublished should only work for hierarchical post types
+ if ( $include_unpublished ) {
- // Flat post types are not allowed to include unpublished, as perms can be set for drafts
- if ( $post_type ) {
+ // Flat post types are not allowed to include unpublished, as perms can be set for drafts
+ if ( $post_type ) {
- $pto = get_post_type_object( $post_type );
+ $pto = get_post_type_object( $post_type );
- if ( $pto->hierarchical ) {
+ if ( $pto->hierarchical ) {
- // The `$post_type_clause` statement is prepared above and can be considered safe here.
- $post_status_clause = "OR (post_status IN ('draft','pending') $post_type_clause)";
+ $post_status_clause = "OR (post_status IN ('draft','pending') $post_type_clause)";
- }
- } else {
+ }
+ } else {
- $post_status_clause = "OR post_status IN ('draft','pending')";
+ $post_status_clause = "OR post_status IN ('draft','pending')";
- }
- }
+ }
+ }
- // Prepare the first section of the SQL statement.
- $count_query = $wpdb->prepare(
- "SELECT ID FROM {$wpdb->posts} WHERE ( ID IN ( SELECT post_ID FROM {$wpdb->postmeta} WHERE meta_key = %s",
- BU_Group_Permissions::META_KEY
- );
+ // Build group_id IN clause safely
+ $group_ids = array_map( 'intval', $group_ids );
+ $group_in = implode( ',', $group_ids );
- // Build the remaining SQL from previously prepared statements. The `group_ids` array is forced to integer values for safety.
- $count_query .= " AND meta_value IN (" . implode( ',', array_map( 'intval', $group_ids ) ) . ') ) ' . $post_type_clause . ') ' . $post_status_clause;
+ // Final query: find posts whose ID appears in postmeta entries for our group IDs
+ $sql = "SELECT ID FROM {$wpdb->posts} WHERE ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value IN ({$group_in}) ) {$post_type_clause}";
- // Execute query
- $ids = $wpdb->get_col( $count_query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
+ if ( $post_status_clause ) {
+ $sql .= " {$post_status_clause} ";
+ }
- return $ids;
- }
+ // Use prepare for the meta_key substitution
+ $prepared = $wpdb->prepare( $sql, BU_Group_Permissions::META_KEY );
+
+ $ids = $wpdb->get_col( $prepared );
+
+ return $ids;
+ }
/**
* Get allowed post count, optionally filtered by user ID, group or post_type
diff --git a/classes.permissions.php b/classes.permissions.php
index 6c75368..7024e6a 100644
--- a/classes.permissions.php
+++ b/classes.permissions.php
@@ -70,82 +70,91 @@ public static function can_edit_section( WP_User $user, $post_id ) {
}
/**
- * Update permissions for a group
- *
- * @param int $group_id ID of group to modify ACL for
- * @param array $permissions Permissions, as an associative array indexed by post type
- */
- public static function update_group_permissions( $group_id, $permissions ) {
- global $wpdb;
-
- if ( ! is_array( $permissions ) ) {
- return false;
- }
-
- foreach ( $permissions as $post_type => $ids_by_status ) {
-
- if ( ! is_array( $ids_by_status ) ) {
- error_log( "Unexpected value found while updating permissions: $ids_by_status" );
- continue;
- }
-
- // Incoming allowed posts
- $allowed_ids = isset( $ids_by_status['allowed'] ) ? $ids_by_status['allowed'] : array();
-
- if ( ! empty( $allowed_ids ) ) {
-
- // Make sure we don't add allowed meta twice
- $previously_allowed = $wpdb->get_col(
- $wpdb->prepare(
- "SELECT post_id FROM {$wpdb->postmeta} WHERE post_id IN (%s) AND meta_key = %s AND meta_value = %s",
- implode( ',', $allowed_ids ),
- self::META_KEY,
- $group_id
- )
- );
- $additions = array_merge( array_diff( $allowed_ids, $previously_allowed ) );
-
- foreach ( $additions as $post_id ) {
-
- add_post_meta( $post_id, self::META_KEY, $group_id );
- }
- }
-
- // Incoming restricted posts
- $denied_ids = isset( $ids_by_status['denied'] ) ? $ids_by_status['denied'] : array();
-
- if ( ! empty( $denied_ids ) ) {
-
- // Sanitize the list of IDs for direct use in the query.
- $denied_ids = implode( ',', array_map( 'intval', $denied_ids ) );
-
- // Select meta_id's for removal based on incoming posts
- $denied_meta_ids = $wpdb->get_col(
- $wpdb->prepare(
- "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id IN ({$denied_ids}) AND meta_key = %s AND meta_value = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- self::META_KEY,
- $group_id
- )
- );
-
- // Bulk deletion
- if ( ! empty( $denied_meta_ids ) ) {
-
- // Sanitize the list of IDs for direct use in the query.
- $denied_meta_ids = implode( ',', array_map( 'intval', $denied_meta_ids ) );
-
- // Remove allowed status in one query
- $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN ({$denied_meta_ids})" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
-
- // Purge cache
- foreach ( $denied_ids as $post_id ) {
- wp_cache_delete( $post_id, 'post_meta' );
- }
- }
- }
- }
-
- }
+ * Update permissions for a group
+ *
+ * @param int $group_id ID of group to modify ACL for
+ * @param array $permissions Permissions, as an associative array indexed by post type
+ */
+ public static function update_group_permissions( $group_id, $permissions ) {
+ global $wpdb;
+
+ if ( ! is_array( $permissions ) ) {
+ return false;
+ }
+
+ foreach ( $permissions as $post_type => $ids_by_status ) {
+
+ if ( ! is_array( $ids_by_status ) ) {
+ error_log( "Unexpected value found while updating permissions: $ids_by_status" );
+ continue;
+ }
+
+ //
+ // Handle allowed IDs
+ //
+ $allowed_ids = isset( $ids_by_status['allowed'] ) ? $ids_by_status['allowed'] : array();
+ $allowed_ids = array_map( 'intval', (array) $allowed_ids );
+
+ if ( ! empty( $allowed_ids ) ) {
+
+ // Build safe IN list from ints
+ $in = implode( ',', $allowed_ids );
+
+ // Find which of these are already present
+ $previously_allowed = $wpdb->get_col(
+ "SELECT post_id FROM {$wpdb->postmeta} WHERE post_id IN ({$in}) AND meta_key = '"
+ . esc_sql( self::META_KEY ) . "' AND meta_value = '" . esc_sql( $group_id ) . "'"
+ );
+
+ $additions = array_diff( $allowed_ids, (array) $previously_allowed );
+
+ foreach ( $additions as $post_id ) {
+ add_post_meta( $post_id, self::META_KEY, $group_id );
+ // Purge cache for this post's post_meta
+ wp_cache_delete( $post_id, 'post_meta' );
+ }
+ }
+
+ //
+ // Handle denied IDs (remove meta rows)
+ //
+ $denied_ids = isset( $ids_by_status['denied'] ) ? $ids_by_status['denied'] : array();
+ $denied_ids = array_map( 'intval', (array) $denied_ids );
+
+ if ( ! empty( $denied_ids ) ) {
+
+ $in = implode( ',', $denied_ids );
+
+ // Get meta rows so we can delete them and purge relevant post caches
+ $rows = $wpdb->get_results(
+ "SELECT meta_id, post_id FROM {$wpdb->postmeta} WHERE post_id IN ({$in}) AND meta_key = '"
+ . esc_sql( self::META_KEY ) . "' AND meta_value = '" . esc_sql( $group_id ) . "'",
+ OBJECT
+ );
+
+ if ( ! empty( $rows ) ) {
+
+ $meta_ids = array();
+ $post_ids = array();
+
+ foreach ( $rows as $r ) {
+ $meta_ids[] = intval( $r->meta_id );
+ $post_ids[] = intval( $r->post_id );
+ }
+
+ // Execute deletion of postmeta rows
+ $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_id IN (" . implode( ',', $meta_ids ) . ")" );
+
+ // Purge post_meta cache for affected posts
+ foreach ( array_unique( $post_ids ) as $pid ) {
+ wp_cache_delete( $pid, 'post_meta' );
+ }
+ }
+ }
+ }
+
+ return true;
+ }
public static function delete_group_permissions( $group_id ) {
@@ -333,7 +342,7 @@ public function display() {
break;
case 'html':default:
- echo $this->get_posts();
+ echo esc_html( $this->get_posts(), 'bu-section-editing' );
break;
}
@@ -411,8 +420,8 @@ public function get_post_markup( $p ) {
// Publish information
$meta = '';
- $published_label = __( 'Published on', BUSE_TEXTDOMAIN );
- $draft_label = __( 'Draft', BUSE_TEXTDOMAIN );
+ $published_label = __( 'Published on', 'bu-section-editing' );
+ $draft_label = __( 'Draft', 'bu-section-editing' );
switch ( $p['metadata']['post_status'] ) {
@@ -434,7 +443,7 @@ public function get_post_markup( $p ) {
// Perm actions button
$perm_state = $p['metadata']['editable'] ? 'denied' : 'allowed';
- $perm_label = $perm_state == 'allowed' ? __( 'Allow', BUSE_TEXTDOMAIN ) : __( 'Deny', BUSE_TEXTDOMAIN );
+ $perm_label = $perm_state == 'allowed' ? __( 'Allow', 'bu-section-editing' ) : __( 'Deny', 'bu-section-editing' );
$button = sprintf( '', $perm_state, $perm_label );
// Anchor
@@ -472,7 +481,7 @@ public function format_post( $post, $has_children = false ) {
$editable = BU_Group_Permissions::group_can_edit( $this->group->id, $post->ID, 'ignore_global' );
$perm = $editable ? 'allowed' : 'denied';
- $post->post_title = empty( $post->post_title ) ? __( '(no title)', BUSE_TEXTDOMAIN ) : $post->post_title;
+ $post->post_title = empty( $post->post_title ) ? __( '(no title)', 'bu-section-editing' ) : $post->post_title;
$p = array(
'attr' => array(
@@ -486,7 +495,7 @@ public function format_post( $post, $has_children = false ) {
),
'metadata' => array(
'post_id' => $post->ID,
- 'post_date' => date( get_option( 'date_format' ), strtotime( $post->post_date ) ),
+ 'post_date' => gmdate( get_option( 'date_format' ), strtotime( $post->post_date ) ),
'post_status' => $post->post_status,
'editable' => $editable,
'editable-original' => $editable,
@@ -593,7 +602,7 @@ public function display() {
break;
case 'html': default:
- echo $this->get_posts( $this->child_of );
+ echo esc_html($this->get_posts( $this->child_of ), 'bu-section-editing');
break;
}
@@ -737,45 +746,41 @@ protected function format_post( $post, $has_children = false ) {
* Add custom section editable properties to the post objects returned by bu_navigation_get_pages()
*/
public function filter_posts( $posts ) {
- global $wpdb;
+ global $wpdb;
- if ( ( is_array( $posts ) ) && ( count( $posts ) > 0 ) ) {
+ if ( ( is_array( $posts ) ) && ( count( $posts ) > 0 ) ) {
- /* Gather all group post meta in one shot */
- $ids = array_keys( $posts );
+ /* Gather all group post meta in one shot */
+ $ids = array_keys( $posts );
+ $ids = array_map( 'intval', $ids );
+ $in = implode( ',', $ids );
- // Sanitize the list of IDs for direct use in the query.
- $ids = implode( ',', array_map( 'intval', $ids ) );
+ $group_meta = $wpdb->get_results(
+ "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = '"
+ . esc_sql( BU_Group_Permissions::META_KEY ) . "' AND post_id IN ({$in}) AND meta_value = '"
+ . esc_sql( $this->group->id ) . "'",
+ OBJECT_K
+ );
- $group_meta = $wpdb->get_results(
- $wpdb->prepare(
- "SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id IN ({$ids}) AND meta_value = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
- BU_Group_Permissions::META_KEY,
- $this->group->id
- ),
- OBJECT_K
- ); // get results as objects in an array keyed on post_id
+ if ( ! is_array( $group_meta ) ) {
+ $group_meta = array();
+ }
- if ( ! is_array( $group_meta ) ) {
- $group_meta = array();
- }
+ // Append permissions to post object
+ foreach ( $posts as $post ) {
- // Append permissions to post object
- foreach ( $posts as $post ) {
+ $post->editable = false;
- $post->editable = false;
+ if ( array_key_exists( $post->ID, $group_meta ) ) {
+ $perm = $group_meta[ $post->ID ];
- if ( array_key_exists( $post->ID, $group_meta ) ) {
- $perm = $group_meta[ $post->ID ];
+ if ( $perm->meta_value === (string) $this->group->id ) {
+ $post->editable = true;
+ }
+ }
+ }
+ }
- if ( $perm->meta_value === (string) $this->group->id ) {
- $post->editable = true;
- }
- }
- }
- }
-
- return $posts;
-
- }
+ return $posts;
+ }
}
diff --git a/classes.upgrade.php b/classes.upgrade.php
index 2ff389c..8ea8dcc 100644
--- a/classes.upgrade.php
+++ b/classes.upgrade.php
@@ -120,7 +120,7 @@ private function upgrade_03() {
BU_Group_Permissions::META_KEY,
'%:allowed'
)
- );
+ );
foreach ( $allowed_posts as $post ) {
$new_meta_value = preg_replace( $patterns, $replacements, $post->meta_value );
@@ -133,8 +133,7 @@ private function upgrade_03() {
"SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value LIKE %s",
BU_Group_Permissions::META_KEY,
'%denied'
- )
- );
+ ));
// Loop through and update
foreach ( $denied_posts as $post ) {
@@ -183,7 +182,6 @@ private function upgrade_04() {
// Convert to new structure
$group = $gc->add_group( $groupdata );
- // Grab all post IDS that have permissions set for this group
$posts_to_update = $wpdb->get_col(
$wpdb->prepare(
"SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s",
diff --git a/interface/edit-group.php b/interface/edit-group.php
index ce71682..2b170ab 100644
--- a/interface/edit-group.php
+++ b/interface/edit-group.php
@@ -1,21 +1,21 @@