Plugin Directory

Changeset 2529515


Ignore:
Timestamp:
05/11/2021 07:22:31 AM (4 years ago)
Author:
lukasznowicki
Message:

Added one qualifier, changed user capabilities to constants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • postpage-specific-custom-css/tags/0.2.2/post-page-specific-custom-css.php

    r2529500 r2529515  
    1616namespace Phylax\WPPlugin\PPCustomCSS;
    1717
     18use WP_Post;
    1819use const DOING_AUTOSAVE;
    1920
     
    4243
    4344    const NONCE_HIDE_BIRTHDAY = 'ppscc_hide_birthday';
     45
     46    const CAP_MANAGE_OPTIONS = 'manage_options';
     47    const CAP_EDIT_OTHERS_PAGES = 'edit_others_pages';
    4448
    4549    private $isBirthday = false;
     
    545549
    546550    public function current_user_already_seen_message(): bool {
    547         if ( ! current_user_can( 'manage_options' ) ) {
     551        if ( ! current_user_can( self::CAP_MANAGE_OPTIONS ) ) {
    548552            // Always return true for non-administrators
    549553            return true;
     
    612616
    613617    public function add_options_page() {
    614         $sub_menu_suffix = add_submenu_page( self::PARENT_MENU_SLUG, __( 'Post/Page specific custom CSS', 'postpage-specific-custom-css' ), __( 'Post/Page CSS', 'postpage-specific-custom-css' ), 'manage_options', self::MENU_SLUG, [
     618        $sub_menu_suffix = add_submenu_page( self::PARENT_MENU_SLUG, __( 'Post/Page specific custom CSS', 'postpage-specific-custom-css' ), __( 'Post/Page CSS', 'postpage-specific-custom-css' ), self::CAP_MANAGE_OPTIONS, self::MENU_SLUG, [
    615619            $this,
    616620            'options_page_view',
     
    675679            return $content;
    676680        }
    677         /** @var \WP_Post $post */
     681        /** @var WP_Post $post */
    678682        $phylax_ppsccss_single_only = get_post_meta( $post->ID, self::POST_META_SINGLE, true );
    679683        $phylax_ppsccss_css         = get_post_meta( $post->ID, self::POST_META_CSS, true );
     
    722726    }
    723727
    724     public function allowedToView() {
     728    public function allowedToView(): bool {
    725729        $settings      = (array) get_option( self::OPTION_NAME );
    726730        $allow_editors = (bool) ( $settings[ self::OPT_CONTROL_USER_EDITOR ] ?? 0 );
    727731        if (
    728             current_user_can( 'manage_options' ) ||
     732            current_user_can( self::CAP_MANAGE_OPTIONS ) ||
    729733            (
    730734                $allow_editors &&
    731                 current_user_can( 'edit_others_pages' )
     735                current_user_can( self::CAP_EDIT_OTHERS_PAGES )
    732736            )
    733737        ) {
     
    881885    public function init() {
    882886        load_plugin_textdomain( 'postpage-specific-custom-css', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    883         if ( current_user_can( 'manage_options' ) ) {
     887        if ( current_user_can( self::CAP_MANAGE_OPTIONS ) ) {
    884888            $ppscc_birthday = (string) ( get_user_meta( get_current_user_id(), 'ppscc_birthday', true ) ?? '' );
    885889            if ( 'hide' === $ppscc_birthday ) {
     
    894898                    exit;
    895899                }
    896                 if ( ! current_user_can( 'manage_options' ) ) {
     900                if ( ! current_user_can( self::CAP_MANAGE_OPTIONS ) ) {
    897901                    exit;
    898902                }
     
    905909
    906910    public function update_user_meta() {
    907         if ( ! current_user_can( 'manage_options' ) ) {
     911        if ( ! current_user_can( self::CAP_MANAGE_OPTIONS ) ) {
    908912            return;
    909913        }
Note: See TracChangeset for help on using the changeset viewer.