Skip to content

Commit

Permalink
Include and check post ID in Live Editor.
Browse files Browse the repository at this point in the history
Resolves GH-308
  • Loading branch information
gregpriday committed Jan 16, 2017
1 parent 9b42604 commit 1b44eea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 9 additions & 1 deletion inc/live-editor.php
Expand Up @@ -10,7 +10,15 @@
* @return array
*/
function siteorigin_panels_live_editor($value, $post_id, $meta_key){
if( $meta_key == 'panels_data' && current_user_can( 'edit_post', $post_id ) && !empty( $_POST['live_editor_panels_data'] ) ) {
global $post;

if(
$meta_key == 'panels_data' &&
current_user_can( 'edit_post', $post_id ) &&
! empty( $_POST['live_editor_panels_data'] ) &&
( empty( $_POST['live_editor_post_ID'] ) || empty( $post ) || $_POST['live_editor_post_ID'] == $post->ID )

) {
$data = json_decode( wp_unslash( $_POST['live_editor_panels_data'] ), true );

if(
Expand Down
3 changes: 2 additions & 1 deletion js/siteorigin-panels.js
Expand Up @@ -5181,7 +5181,8 @@ module.exports = Backbone.View.extend( {

this.postToIframe(
{
live_editor_panels_data: JSON.stringify( data )
live_editor_panels_data: JSON.stringify( data ),
live_editor_post_ID: this.builder.config.postId
},
this.previewUrl,
this.$('.so-preview')
Expand Down
3 changes: 2 additions & 1 deletion js/siteorigin-panels/view/live-editor.js
Expand Up @@ -242,7 +242,8 @@ module.exports = Backbone.View.extend( {

this.postToIframe(
{
live_editor_panels_data: JSON.stringify( data )
live_editor_panels_data: JSON.stringify( data ),
live_editor_post_ID: this.builder.config.postId
},
this.previewUrl,
this.$('.so-preview')
Expand Down
9 changes: 4 additions & 5 deletions siteorigin-panels.php
Expand Up @@ -902,19 +902,18 @@ function siteorigin_panels_generate_css($post_id, $panels_data = false){
*/
function siteorigin_panels_filter_content( $content ) {
global $post;

if ( empty( $post ) ) return $content;
if ( !apply_filters( 'siteorigin_panels_filter_content_enabled', true ) ) return $content;
if ( ! apply_filters( 'siteorigin_panels_filter_content_enabled', true ) ) return $content;

// Check if this post has panels_data
$panels_data = get_post_meta( $post->ID, 'panels_data', true );
if ( !empty( $panels_data ) ) {
if ( ! empty( $panels_data ) ) {
$panel_content = siteorigin_panels_render( $post->ID );

if ( !empty( $panel_content ) ) {
$content = $panel_content;

if( !is_singular() ) {
if( ! is_singular() ) {
// This is an archive page, so try strip out anything after the more text

if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
Expand Down Expand Up @@ -1638,4 +1637,4 @@ function siteorigin_panels_premium_url() {
}

// Include the live editor file if we're in live editor mode.
if( !empty($_GET['siteorigin_panels_live_editor']) ) require_once plugin_dir_path(__FILE__) . 'inc/live-editor.php';
if( !empty( $_GET['siteorigin_panels_live_editor'] ) ) require_once plugin_dir_path(__FILE__) . 'inc/live-editor.php';

0 comments on commit 1b44eea

Please sign in to comment.