Plugin Directory

Changeset 3322020


Ignore:
Timestamp:
07/03/2025 09:55:08 PM (9 months ago)
Author:
pattihis
Message:

Version 1.4.3

Location:
simple-photo-feed
Files:
34 added
4 edited

Legend:

Unmodified
Added
Removed
  • simple-photo-feed/trunk/README.txt

    r3319558 r3322020  
    66Tested up to: 6.8
    77Requires PHP: 7.2
    8 Stable tag: 1.4.2
     8Stable tag: 1.4.3
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8888Of course! "Simple Photo Feed" is compatible with any theme and plugin that follows WordPress coding standards.
    8989
     90= Who can access and use the Plugin? =
     91
     92Simple 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
    9094== Screenshots ==
    9195
     
    9498
    9599== Changelog ==
     100
     101= 1.4.3 =
     102* Added configurable access control - site administrators can now choose which user roles can access the
     103plugin settings
     104* Default remains administrators only for security
     105* Added filter hook `spf_required_capability` for developers to customize access control
    96106
    97107= 1.4.2 =
  • simple-photo-feed/trunk/admin/class-simple-photo-feed-admin.php

    r3319558 r3322020  
    8787
    8888    /**
     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    /**
    89114     * Register the admin menu
    90115     *
     
    95120        add_menu_page(
    96121            __( 'Simple Photo Feed Settings', 'simple-photo-feed' ),
    97             __( 'Simple Photo Feed', 'simple-photo-feed' ),
    98             'edit_posts',
     122            __( 'Photo Feed', 'simple-photo-feed' ),
     123            $this->get_required_capability(),
    99124            $this->plugin_name,
    100125            array( $this, 'simple_photo_feed_admin_display' ),
     
    110135     */
    111136    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
    112142        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        });
    113183    }
    114184
     
    124194    public function simple_photo_feed_register_settings() {
    125195
    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;
    127214    }
    128215
     
    201288    public function spf_disconnect_user() {
    202289        $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' ) ) {
    204291            wp_send_json_error( esc_html__( 'Unauthorized!', 'simple-photo-feed' ), 403 );
    205292            return;
     
    230317    public function spf_clear_feed_cache() {
    231318        $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' ) ) {
    233320            wp_send_json_error( esc_html__( 'Unauthorized!', 'simple-photo-feed' ), 403 );
    234321            return;
  • simple-photo-feed/trunk/admin/partials/simple-photo-feed-admin-display.php

    r3211228 r3322020  
    5252
    5353    <div class="spf_main_left">
     54        <?php if ( current_user_can( 'manage_options' ) ) : ?>
    5455        <form method="post" action="options.php">
    5556            <?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; ?>
    5661            <?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>'; ?>
    5762            <div class="spf-dual-ring hidden" id="spf-loader"></div>
     
    138143                        </td>
    139144                    </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; ?>
    140158                </tbody>
    141159            </table>
  • simple-photo-feed/trunk/simple-photo-feed.php

    r3319558 r3322020  
    1414 * Plugin URI:        https://wordpress.org/plugins/simple-photo-feed/
    1515 * 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.2
     16 * Version:           1.4.3
    1717 * Requires at least: 5.3.0
    1818 * Tested up to:      6.8
     
    3434 * Current plugin version
    3535 */
    36 define( 'SPF_VERSION', '1.4.2' );
     36define( 'SPF_VERSION', '1.4.3' );
    3737
    3838/**
Note: See TracChangeset for help on using the changeset viewer.