Skip to content

Commit

Permalink
release: fixes
Browse files Browse the repository at this point in the history
Bug Fixes
- Enhanced security
  • Loading branch information
vytisbulkevicius authored Nov 3, 2023
2 parents b213001 + 19c68cd commit 9ac0f92
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 45 deletions.
2 changes: 1 addition & 1 deletion includes/admin/feedzy-rss-feeds-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function enqueue_styles_admin() {
);
wp_enqueue_style( 'wp-block-editor' );
}
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && get_option( 'feedzy_import_tour' ) ) ) {
if ( ! defined( 'TI_CYPRESS_TESTING' ) && ( 'edit' !== $screen->base && 'feedzy_imports' === $screen->post_type && feedzy_show_import_tour() ) ) {
wp_enqueue_script( $this->plugin_name . '_on_boarding', FEEDZY_ABSURL . 'js/Onboarding/import-onboarding.min.js', array( 'react', 'react-dom', 'wp-editor', 'wp-api', 'lodash' ), $this->version, true );
}

Expand Down
12 changes: 7 additions & 5 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,24 +259,26 @@ public function register_import_post_type() {
$args = apply_filters( 'feedzy_imports_args', $args );
register_post_type( 'feedzy_imports', $args );

// Register setting field.
register_setting(
'feedzy_import_tour_settings',
// Register user meta field.
register_meta(
'user',
'feedzy_import_tour',
array(
'type' => 'boolean',
'description' => __( 'Show tour for Feedzy.', 'feedzy-rss-feeds' ),
'show_in_rest' => true,
'single' => true,
'default' => true,
)
);
register_setting(
'feedzy_import_actions_settings',
register_meta(
'user',
'feedzy_hide_action_message',
array(
'type' => 'boolean',
'description' => __( 'Show intro message for Feedzy action popup.', 'feedzy-rss-feeds' ),
'show_in_rest' => true,
'single' => true,
'default' => false,
)
);
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/feedzy-rss-feeds-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function is_block_editor() {
*/
public function register_init() {
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) && 'true' == get_user_option( 'rich_editing' ) ) {
if ( feedzy_current_user_can() && 'true' == get_user_option( 'rich_editing' ) ) {
$this->loader->add_filter( 'mce_external_plugins', $this, 'feedzy_tinymce_plugin', 10, 1 );
$this->loader->add_filter( 'mce_buttons', $this, 'feedzy_register_mce_button', 10, 1 );
$this->loader->add_filter( 'mce_external_languages', $this, 'feedzy_add_tinymce_lang', 10, 1 );
Expand Down
23 changes: 8 additions & 15 deletions includes/feedzy-rss-feeds-feed-tweaks.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,20 +534,13 @@ function feedzy_current_user_can() {
}

/**
* Handle user capability.
* Show import tour.
*
* @return bool
*/
function feedzy_handle_user_cap() {
add_filter(
'user_has_cap',
function ( $allcaps, $caps, $args, $user ) {
$capability = apply_filters( 'feedzy_admin_menu_capability', 'publish_posts' );
if ( ! empty( $allcaps[ $capability ] ) ) {
$allcaps['manage_options'] = ! empty( $allcaps[ $capability ] );
}
return $allcaps;
},
10,
4
);
function feedzy_show_import_tour() {
if ( is_user_logged_in() && 'no' === get_option( 'feedzy_import_tour', 'no' ) ) {
return get_user_meta( get_current_user_id(), 'feedzy_import_tour', true );
}
return false;
}
add_action( 'rest_api_init', 'feedzy_handle_user_cap' );
2 changes: 1 addition & 1 deletion includes/views/import-metabox-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

global $post;
?>
<?php if ( get_option( 'feedzy_import_tour' ) && ! defined( 'TI_CYPRESS_TESTING' ) ) : ?>
<?php if ( feedzy_show_import_tour() && ! defined( 'TI_CYPRESS_TESTING' ) ) : ?>
<div id="fz-on-boarding"></div>
<?php endif; ?>
<div id="fz-feedback-modal"></div>
Expand Down
21 changes: 12 additions & 9 deletions js/ActionPopup/action-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {

const ActionModal = () => {
// useRef
const settingsRef = useRef(null);
const userRef = useRef(null);
const feedzyImportRef = useRef(null);
// State
const [ isOpen, setOpen ] = useState(false);
Expand All @@ -41,9 +41,9 @@ const ActionModal = () => {

useEffect( () => {
window.wp.api.loadPromise.then( () => {
// Fetch settings.
settingsRef.current = new window.wp.api.models.Settings();
settingsRef.current.fetch();
// Fetch user.
userRef.current = new window.wp.api.models.User( { id: 'me' } );
userRef.current.fetch();
});
}, []);

Expand Down Expand Up @@ -104,15 +104,18 @@ const ActionModal = () => {
if ( isOpen ) {
hideIntroMessage(false);
}
const model = new window.wp.api.models.Settings({
const model = new window.wp.api.models.User({
// eslint-disable-next-line camelcase
feedzy_hide_action_message: true
id: 'me',
meta: {
feedzy_hide_action_message: true
}
});

const save = model.save();

save.success( () => {
settingsRef.current.fetch();
userRef.current.fetch();
});

save.error( ( response ) => {
Expand Down Expand Up @@ -162,8 +165,8 @@ const ActionModal = () => {
document.querySelectorAll( '[data-action_popup]' ).forEach( actionItem => {
actionItem.addEventListener( 'click', ( event ) => {
event.preventDefault();
if ( settingsRef.current ) {
if ( ! settingsRef.current.attributes.feedzy_hide_action_message ) {
if ( userRef.current ) {
if ( ! userRef.current.attributes.meta.feedzy_hide_action_message ) {
hideActionIntroMessage();
} else {
hideIntroMessage(true);
Expand Down
2 changes: 1 addition & 1 deletion js/ActionPopup/action-popup.min.js

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions js/Onboarding/import-onboarding.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const Onboarding = () => {
const [ isOpen, setOpen ] = useState( true );
const [ runTour, setRunTour ] = useState( false );

const settingsRef = useRef( null );
const userRef = useRef( null );

useEffect( () => {
window.wp.api.loadPromise.then( () => {
settingsRef.current = new window.wp.api.models.Settings();
userRef.current = new window.wp.api.models.User( { id: 'me' } );
});
}, []);

Expand Down Expand Up @@ -66,15 +66,18 @@ const Onboarding = () => {
return;
}

const model = new window.wp.api.models.Settings({
const model = new window.wp.api.models.User({
// eslint-disable-next-line camelcase
feedzy_import_tour: false
id: 'me',
meta: {
feedzy_import_tour: false
}
});

const save = model.save();

save.success( () => {
settingsRef.current.fetch();
userRef.current.fetch();
});

save.error( ( response ) => {
Expand Down
14 changes: 7 additions & 7 deletions js/Onboarding/import-onboarding.min.js

Large diffs are not rendered by default.

0 comments on commit 9ac0f92

Please sign in to comment.