Changeset 3322020
- Timestamp:
- 07/03/2025 09:55:08 PM (9 months ago)
- Location:
- simple-photo-feed
- Files:
-
- 34 added
- 4 edited
-
tags/1.4.3 (added)
-
tags/1.4.3/LICENSE.txt (added)
-
tags/1.4.3/README.txt (added)
-
tags/1.4.3/admin (added)
-
tags/1.4.3/admin/class-simple-photo-feed-admin.php (added)
-
tags/1.4.3/admin/css (added)
-
tags/1.4.3/admin/css/simple-photo-feed-admin.css (added)
-
tags/1.4.3/admin/index.php (added)
-
tags/1.4.3/admin/js (added)
-
tags/1.4.3/admin/js/simple-photo-feed-admin.js (added)
-
tags/1.4.3/admin/partials (added)
-
tags/1.4.3/admin/partials/simple-photo-feed-admin-display.php (added)
-
tags/1.4.3/includes (added)
-
tags/1.4.3/includes/class-simple-photo-feed-activator.php (added)
-
tags/1.4.3/includes/class-simple-photo-feed-api.php (added)
-
tags/1.4.3/includes/class-simple-photo-feed-deactivator.php (added)
-
tags/1.4.3/includes/class-simple-photo-feed-i18n.php (added)
-
tags/1.4.3/includes/class-simple-photo-feed-loader.php (added)
-
tags/1.4.3/includes/class-simple-photo-feed.php (added)
-
tags/1.4.3/includes/index.php (added)
-
tags/1.4.3/index.php (added)
-
tags/1.4.3/languages (added)
-
tags/1.4.3/languages/simple-photo-feed.pot (added)
-
tags/1.4.3/public (added)
-
tags/1.4.3/public/class-simple-photo-feed-public.php (added)
-
tags/1.4.3/public/css (added)
-
tags/1.4.3/public/css/simple-photo-feed-public.css (added)
-
tags/1.4.3/public/index.php (added)
-
tags/1.4.3/public/js (added)
-
tags/1.4.3/public/js/simple-photo-feed-public.js (added)
-
tags/1.4.3/public/partials (added)
-
tags/1.4.3/public/partials/simple-photo-feed-public-display.php (added)
-
tags/1.4.3/simple-photo-feed.php (added)
-
tags/1.4.3/uninstall.php (added)
-
trunk/README.txt (modified) (3 diffs)
-
trunk/admin/class-simple-photo-feed-admin.php (modified) (6 diffs)
-
trunk/admin/partials/simple-photo-feed-admin-display.php (modified) (2 diffs)
-
trunk/simple-photo-feed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
simple-photo-feed/trunk/README.txt
r3319558 r3322020 6 6 Tested up to: 6.8 7 7 Requires PHP: 7.2 8 Stable tag: 1.4. 28 Stable tag: 1.4.3 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 88 88 Of course! "Simple Photo Feed" is compatible with any theme and plugin that follows WordPress coding standards. 89 89 90 = Who can access and use the Plugin? = 91 92 Simple Photo Feed includes configurable access control that allows site administrators to choose which user roles can access and configure the plugin. By default, the plugin remains secure and only allows administrators (`manage_options` capability) to access the plugin settings. This ensures that sensitive Instagram API credentials and feed configuration remain protected. 93 90 94 == Screenshots == 91 95 … … 94 98 95 99 == Changelog == 100 101 = 1.4.3 = 102 * Added configurable access control - site administrators can now choose which user roles can access the 103 plugin settings 104 * Default remains administrators only for security 105 * Added filter hook `spf_required_capability` for developers to customize access control 96 106 97 107 = 1.4.2 = -
simple-photo-feed/trunk/admin/class-simple-photo-feed-admin.php
r3319558 r3322020 87 87 88 88 /** 89 * Get the required capability for accessing the plugin 90 * 91 * @since 1.4.3 92 * @return string The required capability 93 */ 94 public function get_required_capability() { 95 $options = get_option( 'spf_main_settings', array() ); 96 $capability = isset( $options['required_capability'] ) ? $options['required_capability'] : 'manage_options'; 97 98 // Ensure the capability is valid and secure. 99 $valid_capabilities = array( 'manage_options', 'edit_posts', 'publish_posts' ); 100 if ( ! in_array( $capability, $valid_capabilities, true ) ) { 101 $capability = 'manage_options'; 102 } 103 104 /** 105 * Filter the required capability for accessing the plugin 106 * 107 * @since 1.4.3 108 * @param string $capability The required capability 109 */ 110 return apply_filters( 'spf_required_capability', $capability ); 111 } 112 113 /** 89 114 * Register the admin menu 90 115 * … … 95 120 add_menu_page( 96 121 __( 'Simple Photo Feed Settings', 'simple-photo-feed' ), 97 __( ' SimplePhoto Feed', 'simple-photo-feed' ),98 'edit_posts',122 __( 'Photo Feed', 'simple-photo-feed' ), 123 $this->get_required_capability(), 99 124 $this->plugin_name, 100 125 array( $this, 'simple_photo_feed_admin_display' ), … … 110 135 */ 111 136 public function simple_photo_feed_admin_display() { 137 // Handle custom form submission for non-administrators. 138 if ( ! current_user_can( 'manage_options' ) && isset( $_POST['spf_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['spf_nonce'] ) ), 'spf_save_settings' ) ) { 139 $this->handle_custom_form_submission(); 140 } 141 112 142 include_once 'partials/simple-photo-feed-admin-display.php'; 143 } 144 145 /** 146 * Handle form submission for non-administrators 147 * 148 * @since 1.4.3 149 */ 150 private function handle_custom_form_submission() { 151 $options = get_option( 'spf_main_settings', array() ); 152 153 // Only allow updating specific fields for non-administrators. 154 if ( isset( $_POST['spf_main_settings']['cron_time'] ) ) { 155 $options['cron_time'] = sanitize_text_field( wp_unslash( $_POST['spf_main_settings']['cron_time'] ) ); 156 } 157 158 if ( isset( $_POST['spf_main_settings']['token'] ) ) { 159 $options['token'] = sanitize_text_field( wp_unslash( $_POST['spf_main_settings']['token'] ) ); 160 } 161 162 if ( isset( $_POST['spf_main_settings']['user_id'] ) ) { 163 $options['user_id'] = sanitize_text_field( wp_unslash( $_POST['spf_main_settings']['user_id'] ) ); 164 } 165 166 if ( isset( $_POST['spf_main_settings']['auth'] ) ) { 167 $options['auth'] = sanitize_text_field( wp_unslash( $_POST['spf_main_settings']['auth'] ) ); 168 } 169 170 // Set the capability based on current user's role. 171 if ( current_user_can( 'edit_posts' ) ) { 172 $options['required_capability'] = 'edit_posts'; // Editors and above. 173 } elseif ( current_user_can( 'publish_posts' ) ) { 174 $options['required_capability'] = 'publish_posts'; // Authors and above. 175 } 176 177 update_option( 'spf_main_settings', $options ); 178 179 // Add success message. 180 add_action( 'admin_notices', function() { 181 echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved successfully!', 'simple-photo-feed' ) . '</p></div>'; 182 }); 113 183 } 114 184 … … 124 194 public function simple_photo_feed_register_settings() { 125 195 126 register_setting( 'spf_main_settings', 'spf_main_settings' ); 196 register_setting( 'spf_main_settings', 'spf_main_settings', array( $this, 'sanitize_settings' ) ); 197 } 198 199 /** 200 * Sanitize and validate settings before saving 201 * 202 * @since 1.4.3 203 * @param array $input The input array from the form. 204 * @return array The sanitized input array. 205 */ 206 public function sanitize_settings( $input ) { 207 // Only administrators can modify access control settings. 208 if ( ! current_user_can( 'manage_options' ) ) { 209 // Set the capability based on current user's role. 210 $input['required_capability'] = current_user_can( 'edit_posts' ) ? 'edit_posts' : 'publish_posts'; 211 } 212 213 return $input; 127 214 } 128 215 … … 201 288 public function spf_disconnect_user() { 202 289 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; 203 if ( ! current_user_can( 'edit_posts') || ! wp_verify_nonce( $nonce, 'simple-photo-feed-nonce' ) ) {290 if ( ! current_user_can( $this->get_required_capability() ) || ! wp_verify_nonce( $nonce, 'simple-photo-feed-nonce' ) ) { 204 291 wp_send_json_error( esc_html__( 'Unauthorized!', 'simple-photo-feed' ), 403 ); 205 292 return; … … 230 317 public function spf_clear_feed_cache() { 231 318 $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; 232 if ( ! current_user_can( 'edit_posts') || ! wp_verify_nonce( $nonce, 'simple-photo-feed-nonce' ) ) {319 if ( ! current_user_can( $this->get_required_capability() ) || ! wp_verify_nonce( $nonce, 'simple-photo-feed-nonce' ) ) { 233 320 wp_send_json_error( esc_html__( 'Unauthorized!', 'simple-photo-feed' ), 403 ); 234 321 return; -
simple-photo-feed/trunk/admin/partials/simple-photo-feed-admin-display.php
r3211228 r3322020 52 52 53 53 <div class="spf_main_left"> 54 <?php if ( current_user_can( 'manage_options' ) ) : ?> 54 55 <form method="post" action="options.php"> 55 56 <?php settings_fields( 'spf_main_settings' ); ?> 57 <?php else : ?> 58 <form method="post" action=""> 59 <?php wp_nonce_field( 'spf_save_settings', 'spf_nonce' ); ?> 60 <?php endif; ?> 56 61 <?php echo (bool) $options['auth'] ? '' : '<p>' . esc_html__( 'You need an access token for the official Instagram API. Please click the authorize button below to get one or visit our ', 'simple-photo-feed' ) . '<a href="' . esc_url( $uri ) . '" target="_blank">Token Generator</a></p>'; ?> 57 62 <div class="spf-dual-ring hidden" id="spf-loader"></div> … … 138 143 </td> 139 144 </tr> 145 <?php if ( current_user_can( 'manage_options' ) ) : ?> 146 <tr> 147 <th><?php esc_html_e( 'Access Control', 'simple-photo-feed' ); ?></th> 148 <td> 149 <select name='spf_main_settings[required_capability]' id='spf_required_capability'> 150 <option value='manage_options' <?php selected( esc_attr( $options['required_capability'] ?? 'manage_options' ), 'manage_options' ); ?>><?php esc_html_e( 'Administrators only', 'simple-photo-feed' ); ?></option> 151 <option value='edit_posts' <?php selected( esc_attr( $options['required_capability'] ?? 'manage_options' ), 'edit_posts' ); ?>><?php esc_html_e( 'Editors and above', 'simple-photo-feed' ); ?></option> 152 <option value='publish_posts' <?php selected( esc_attr( $options['required_capability'] ?? 'manage_options' ), 'publish_posts' ); ?>><?php esc_html_e( 'Authors and above', 'simple-photo-feed' ); ?></option> 153 </select> 154 <p class="description"><?php esc_html_e( 'Choose which user roles can access and configure this plugin.', 'simple-photo-feed' ); ?></p> 155 </td> 156 </tr> 157 <?php endif; ?> 140 158 </tbody> 141 159 </table> -
simple-photo-feed/trunk/simple-photo-feed.php
r3319558 r3322020 14 14 * Plugin URI: https://wordpress.org/plugins/simple-photo-feed/ 15 15 * Description: Simple Photo Feed provides an easy way to connect to your Instagram account and display your photos in your WordPress site. 16 * Version: 1.4. 216 * Version: 1.4.3 17 17 * Requires at least: 5.3.0 18 18 * Tested up to: 6.8 … … 34 34 * Current plugin version 35 35 */ 36 define( 'SPF_VERSION', '1.4. 2' );36 define( 'SPF_VERSION', '1.4.3' ); 37 37 38 38 /**
Note: See TracChangeset
for help on using the changeset viewer.