Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
davseve committed Jun 7, 2024
1 parent 9717f67 commit b1d4ce7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
17 changes: 17 additions & 0 deletions assets/dev/js/editor/components/dynamic-tags/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ module.exports = elementorModules.Module.extend( {
} );
},

loadSingleCacheRequest( request ) {
elementorCommon.ajax.addRequest( 'render_tags_single', {
data: {
post_id: elementor.config.document.id,
tags: Object.keys( request ),
},
success: ( data ) => {
this.cache = {
...this.cache,
...data,
};
},
} );

return this.cache;
},

refreshCacheFromServer( callback ) {
this.cacheCallbacks.push( callback );

Expand Down
12 changes: 11 additions & 1 deletion assets/dev/js/editor/elements/views/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,17 @@ BaseElementView = BaseContainer.extend( {
dynamicSettings = { active: true };

if ( valueToParse ) {
return elementor.dynamicTags.parseTagsText( valueToParse, dynamicSettings, elementor.dynamicTags.getTagDataContent );
try {
return elementor.dynamicTags.parseTagsText( valueToParse, dynamicSettings, elementor.dynamicTags.getTagDataContent );
} catch {
// return false;
const request = elementor.dynamicTags.createCacheKey( this ); // This this is incorrect, we should add the tag.js this of build a dedicated this.
console.log( { request } );
elementor.dynamicTags.loadSingleCacheRequest( request );

console.log( 'cache:', elementor.dynamicTags.cache )

}
}

return settings.attributes.item_title; // Default title
Expand Down
35 changes: 35 additions & 0 deletions core/dynamic-tags/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,39 @@ public function ajax_render_tags( $data ) {
return $tags_data;
}

/**
* @since 2.0.0
* @access public
*
* @throws \Exception If post ID is missing.
* @throws \Exception If current user don't have permissions to edit the post.
*/
public function ajax_render_tags_single( $data ) {
if ( empty( $data['post_id'] ) ) {
throw new \Exception( 'Missing post id.' );
}

if ( ! User::is_current_user_can_edit( $data['post_id'] ) ) {
throw new \Exception( 'Access denied.' );
}

Plugin::$instance->db->switch_to_post( $data['post_id'] );

$tags_data = [];

$tag_key_parts = explode( '-', $data['tag'] );

$tag_name = base64_decode( $tag_key_parts[0] );

$tag_settings = json_decode( urldecode( base64_decode( $tag_key_parts[1] ) ), true );

$tag = $this->create_tag( null, $tag_name, $tag_settings );

$tags_data[ $data['tag'] ] = $tag->get_content();

return $tags_data;
}

/**
* @since 2.0.0
* @access public
Expand Down Expand Up @@ -495,6 +528,8 @@ public function after_enqueue_post_css( $css_file ) {
*/
public function register_ajax_actions( Ajax $ajax ) {
$ajax->register_ajax_action( 'render_tags', [ $this, 'ajax_render_tags' ] );
$ajax->register_ajax_action( 'render_tags_single', [ $this, 'ajax_render_tags_single' ] );

}

/**
Expand Down

0 comments on commit b1d4ce7

Please sign in to comment.