← Back
Editing: sidebar.js
"use strict"; ( function( wp ) { var registerPlugin = wp.plugins.registerPlugin; var PluginSidebar = wp.editor.PluginSidebar; var el = wp.element.createElement; registerPlugin( 'twitomatic-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('twitomatic_submit_post').setAttribute('disabled','disabled'); document.getElementById("twitomatic_span").innerHTML = 'Posting status: Submitting... (please do not close or refresh this page) '; var data = { action: 'twitomatic_post_now', id: postId }; jQuery.post(ajaxurl, data, function(response) { document.getElementById('twitomatic_submit_post').removeAttribute('disabled'); document.getElementById("twitomatic_span").innerHTML = 'Posting status: Done! '; }).fail( function(xhr) { document.getElementById("twitomatic_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: 'twitomatic-sidebar', icon: 'twitter', title: 'Twitomatic 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 Twitter ' ), el( 'input', { type:'button', id:'twitomatic_submit_post', value:'Post To Twitter Now!', onClick: updateMessage, className: 'coderevolution_gutenberg_button button button-primary' } ), el( 'br' ), el( 'br' ), el( 'div', {id:'twitomatic_span'}, 'Posting status: idle' ) ) ); }, } ); } )( window.wp );
Save File
Cancel