PluginProbe
Groups – Memberships and Access Control / 4.7.1
Groups – Memberships and Access Control v4.7.1
4.7.1 4.7.0 4.6.0 4.5.0 4.4.0 4.3.0 trunk 1.0.0-beta-1 1.0.0-beta-2 1.0.0-beta-3 1.0.0-beta-3b 1.0.0-beta-3c 1.0.0-beta-3d 1.1.4 1.1.5 1.10.0 1.10.1 1.10.2 1.10.3 1.11.0 1.11.1 1.11.2 1.11.3 1.12.0 1.13.0 All 131 releases
← All changes | lib/core/class-groups-group-capability.php +31 -17 1.10.14.7.1 View file →
@@ -22,8 +22,10 @@
22 22 if ( !defined( 'ABSPATH' ) ) {
23 23 exit;
24 24 }
25 25
26 +// phpcs:disable PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
27 +
26 28 /**
27 29 * Group Capability OPM
28 30 */
29 31 class Groups_Group_Capability {
@@ -30,9 +32,9 @@
30 32
31 33 /**
32 34 * Hook into appropriate actions when needed.
33 35 * For now, this does nothing.
34 - *
36 + *
35 37 * @see Groups_Group::delete()
36 38 */
37 39 public static function init() {
38 40 // Note that group-capabilities are deleted when a group is deleted.
@@ -39,18 +41,22 @@
39 41 }
40 42
41 43 /**
42 44 * Persist a group-capability relation.
43 - *
45 + *
44 46 * @param array $map attributes - must provide group_id and capability_id
47 + *
45 48 * @return true on success, otherwise false
46 49 */
47 50 public static function create( $map ) {
48 51
49 52 global $wpdb;
50 - extract( $map );
53 +
51 54 $result = false;
52 55
56 + $group_id = isset( $map['group_id'] ) ? $map['group_id'] : null;
57 + $capability_id = isset( $map['capability_id'] ) ? $map['capability_id'] : null;
58 +
53 59 // avoid nonsense requests
54 60 if ( !empty( $group_id ) && !empty( $capability_id) ) {
55 61 // make sure group and capability exist
56 62 if ( Groups_Group::read( $group_id ) && Groups_Capability::read( $capability_id ) ) {
@@ -57,9 +63,9 @@
57 63 $group_capability_table = _groups_get_tablename( 'group_capability' );
58 64 // don't try to create duplicate entries
59 65 // also it would raise an error for duplicate PK
60 66 if ( 0 === intval( $wpdb->get_var( $wpdb->prepare(
61 - "SELECT COUNT(*) FROM $group_capability_table WHERE group_id = %d AND capability_id = %d",
67 + "SELECT COUNT(*) FROM $group_capability_table WHERE group_id = %d AND capability_id = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
62 68 Groups_Utility::id( $group_id ),
63 69 Groups_Utility::id( $capability_id )
64 70 ) ) ) ) {
65 71 $data = array(
@@ -68,9 +74,9 @@
68 74 );
69 75 $formats = array( '%d', '%d' );
70 76 if ( $wpdb->insert( $group_capability_table, $data, $formats ) ) {
71 77 $result = true;
72 - do_action( "groups_created_group_capability", $group_id, $capability_id );
78 + do_action( 'groups_created_group_capability', $group_id, $capability_id );
73 79 }
74 80 }
75 81 }
76 82 }
@@ -78,11 +84,12 @@
78 84 }
79 85
80 86 /**
81 87 * Retrieve a group-capability relation.
82 - *
88 + *
83 89 * @param int $group_id group's id
84 90 * @param int $capability_id capability's id
91 + *
85 92 * @return object upon success, otherwise false
86 93 */
87 94 public static function read( $group_id, $capability_id ) {
88 95 global $wpdb;
@@ -89,9 +96,9 @@
89 96 $result = false;
90 97
91 98 $group_capability_table = _groups_get_tablename( 'group_capability' );
92 99 $group_capability = $wpdb->get_row( $wpdb->prepare(
93 - "SELECT * FROM $group_capability_table WHERE group_id = %d AND capability_id = %d",
100 + "SELECT * FROM $group_capability_table WHERE group_id = %d AND capability_id = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
94 101 Groups_Utility::id( $group_id ),
95 102 Groups_Utility::id( $capability_id )
96 103 ) );
97 104 if ( $group_capability !== null ) {
@@ -101,21 +108,27 @@
101 108 }
102 109
103 110 /**
104 111 * Update group-capability relation.
105 - *
112 + *
106 113 * This changes nothing so as of now it's pointless to even call this.
107 - *
114 + *
108 115 * @param array $map
116 + *
109 117 * @return true if successful, false otherwise
110 118 */
111 119 public static function update( $map ) {
112 120 $result = false;
113 - if ( !empty( $group_id ) && !empty( $capability_id) ) {
114 - // make sure group and capability exist
115 - if ( Groups_Group::read( $group_id ) && Groups_Capability::read( $capability_id ) ) {
116 - $result = true;
117 - do_action( "groups_updated_group_capability", $group_id, $capability_id );
121 + // @since 3.0.0 do not process until this actually changes anything
122 + if ( false ) {
123 + $group_id = isset( $map['group_id'] ) ? $map['group_id'] : null;
124 + $capability_id = isset( $map['capability_id'] ) ? $map['capability_id'] : null;
125 + if ( !empty( $group_id ) && !empty( $capability_id) ) {
126 + // make sure group and capability exist
127 + if ( Groups_Group::read( $group_id ) && Groups_Capability::read( $capability_id ) ) {
128 + $result = true;
129 + do_action( 'groups_updated_group_capability', $group_id, $capability_id );
130 + }
118 131 }
119 132 }
120 133 return $result;
121 134 }
@@ -121,11 +134,12 @@
121 134 }
122 135
123 136 /**
124 137 * Remove group-capability relation.
125 - *
138 + *
126 139 * @param int $group_id
127 140 * @param int $capability_id
141 + *
128 142 * @return true if successful, false otherwise
129 143 */
130 144 public static function delete( $group_id, $capability_id ) {
131 145
@@ -138,9 +152,9 @@
138 152 // allow resolving the relationship after they have been deleted
139 153 $group_capability_table = _groups_get_tablename( 'group_capability' );
140 154 // get rid of it
141 155 $rows = $wpdb->query( $wpdb->prepare(
142 - "DELETE FROM $group_capability_table WHERE group_id = %d AND capability_id = %d",
156 + "DELETE FROM $group_capability_table WHERE group_id = %d AND capability_id = %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
143 157 Groups_Utility::id( $group_id ),
144 158 Groups_Utility::id( $capability_id )
145 159 ) );
146 160 // must have affected a row, otherwise no great success
@@ -145,9 +159,9 @@
145 159 ) );
146 160 // must have affected a row, otherwise no great success
147 161 $result = ( $rows !== false ) && ( $rows > 0 );
148 162 if ( $result ) {
149 - do_action( "groups_deleted_group_capability", $group_id, $capability_id );
163 + do_action( 'groups_deleted_group_capability', $group_id, $capability_id );
150 164 }
151 165 }
152 166 return $result;
153 167 }