• Resolved wilcosky

    (@wilcosky)


    I know that one can select quick edit and move a post from draft to published. But, I’m wondering if anyone is aware of a plug-in which would allow you to do a one-click to publish type action. Imagine looking at a list of posts, some published, some not, and then being able to, “click,” that one’s published now… “click,” and now that one’s published.

    • This topic was modified 3 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t see a plugin for this, but I’ve done it below with JavaScript. This adds a Quick Publish button next to Quick Edit. Add it to your functions file or use the Code Snippets plugin.

    <?php
    add_action('admin_footer', 'wpsf_add_quick_publish', 100);
    function wpsf_add_quick_publish()
    { ?>
      <script>
        (function($) {
          // Add a Quick Publish button
          var quickPublishButton = '' +
            '<span class="quick-publish">' +
            '  <a href="javascript:;">Quick Publish</a>' +
            '  | ' +
            '</span>';
    
          $('.row-actions > .inline').after(quickPublishButton);
    
          // When Quick Publish is clicked...
          $('.quick-publish').click(function() {
    
            // Open Quick Edit
            $(this).closest('.row-actions').find('.editinline').click();
    
            // Wait a moment for Quick Edit to open
            setTimeout(() => {
    
              // Select Published from the Status dropdown
              $('.inline-editor select[name="_status"]').val('publish');
    
              // Click Update
              $('.inline-editor .save').click();
    
            }, 500);
    
          });
        })(jQuery);
      </script>
    <?php
    }
    Thread Starter wilcosky

    (@wilcosky)

    Very cool, thank you! I’ve also always seen and heard about the code snippets plugin but never tried it. I decided to try it out. It’s very nice. Sure, you can pop these things into functions.php, but this is a nice visually organized way to do it.

    But, after saving this snippet I got a blank screen and the URL has code error in it. However, the code works and there no errors in the console. And so I’m hoping it’s just a bug with the code snippets plugin or a conflict with another plugin. I guess if everything works and there are no errors showing I’ll just live with it.

    You got a blank screen after clicking Save Changes and Activate on the snippet edit screen? I tested it again on a clean install with just Twenty Twenty One theme and the Code Snippets plugin and it works without issue. So that does point to a theme or plugin conflict.

    Happy to help! ?? This was a fun scripting exercise.

    Thread Starter wilcosky

    (@wilcosky)

    Thanks for the testing that really quick! Yes, it’s definitely a plugin conflict then. I’ll do the old deactivate and reactivate plugins one at a time at some point.

    The code you provided works great!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Quick Publish’ is closed to new replies.