← Back
Editing: sidebar.js
"use strict"; ( function( wp ) { var registerPlugin = wp.plugins.registerPlugin; var PluginSidebar = wp.editor.PluginSidebar; var el = wp.element.createElement; registerPlugin( 'fbomatic-sidebar', { render: function() { function updateMessage( ) { var postId = wp.data.select("core/editor").getCurrentPostId(); if (confirm("Are you sure you want to submit this post now?") == true) { document.getElementById('fbomatic_submit_post').setAttribute('disabled','disabled'); document.getElementById("fbomatic_span").innerHTML = 'Posting status: Submitting... (please do not close or refresh this page) '; var data = { action: 'fbomatic_post_now', id: postId }; jQuery.post(ajaxurl, data, function(response) { document.getElementById('fbomatic_submit_post').removeAttribute('disabled'); document.getElementById("fbomatic_span").innerHTML = 'Posting status: Done! '; }).fail( function(xhr) { document.getElementById("fbomatic_span").innerHTML = 'Error, please check the plugin\'s \'Activity and Logging\' menu for details!'; console.log('Error occured in processing: ' + xhr.statusText + ' - please check plugin\'s \'Activity and Logging\' menu for details.'); }); } else { return; } } return el( PluginSidebar, { name: 'fbomatic-sidebar', icon: 'facebook', title: 'Fbomatic Post Publisher', }, el( 'div', (wp.blockEditor?.useBlockProps || wp.editor?.useBlockProps) ? (wp.blockEditor?.useBlockProps || wp.editor?.useBlockProps)({ className: 'coderevolution_gutenberg_div' }) : { className: 'coderevolution_gutenberg_div' }, el( 'h4', { className: 'coderevolution_gutenberg_title' }, 'Publish Post to Facebook ' ), el( 'input', { type:'button', id:'fbomatic_submit_post', value:'Post To Facebook Now!', onClick: updateMessage, className: 'coderevolution_gutenberg_button button button-primary' } ), el( 'br' ), el( 'br' ), el( 'div', {id:'fbomatic_span'}, 'Posting status: idle' ) ) ); }, } ); } )( window.wp );
Save File
Cancel