-2

In Wordpress admin, looking at a custom post type list screen enter image description here

Task: I need to copy the text of the column "Shortcode" (the text is already shown in the list).

Problem: I cannot access the text as the activated plugin "Post Types Order" inhibits overlaying the text by showing me a mouse pointer as part of some means to move the post to some other position (a feature I need)

My idea: When hovering the mouse over a post a number of command-buttons ("Edit", "QuickEdit" and "Trash") show up on the left hand side as can be seen here enter image description here

An additional command-button "Copy Shortcode" to this set of commands could do the job for me.

Question: How do I add a button to this list right next to "Trash"? (copying to the clipboard using Javascript should be ok)

JohnGalt
  • 37
  • 6
  • another alternative: what i did in the past is add another column in the table and add the shortcode text there, from there you can just copy paste – Kevin Sep 15 '17 at 07:21
  • here's an hook example for the list https://wordpress.stackexchange.com/questions/253640/adding-custom-columns-to-custom-post-types – Kevin Sep 15 '17 at 07:23
  • Thanks for the answer but sorry, it misses my question. I don't want to add a column but a command-button. I added some info to my question. – JohnGalt Sep 15 '17 at 11:04
  • The text you wish to copy being the shortcode text where the arrow is? – ProEvilz Sep 15 '17 at 11:36
  • In regards to your main question, you ask how to add a button to the list, but do you mean to the edit/quick edit/trash in the **posts** section or to add a button to the list of buttons you want to add to the custom post type section? – ProEvilz Sep 15 '17 at 11:38
  • Yes: I want to be able to copy the text in the Shortcode-column by a button in the collection I mentioned, next to "Trash" – JohnGalt Sep 15 '17 at 11:44

1 Answers1

1

I came up with a more comfortable solution that now fills the column "Shortcode" with hyperlinks of the shortcode text. Thus a simple click on the desired shortcode copies the shortcode-text to the clipboard

enter image description here

Here is the code:

// add column 'Shortcode' in admin 'Layouts' list page
    // filter & action
    add_filter( 'manage_posts_columns', 'jg_add_id_column', 5 );
    add_action( 'manage_posts_custom_column', 'jg_id_column_content', 5, 2 );

    //add_filter( 'manage_et_pb_section_columns', 'jg_add_id_column', 5 );
    //add_action( 'manage_et_pb_section_custom_column', 'jg_id_column_content', 5, 2 );

    // display column title
    function jg_add_id_column( $columns ) {
      if( get_post_type( $post_id ) == 'et_pb_layout') {
         $columns['jg_id'] = 'Shortcode';
      }
      return $columns;
    }

    // display column value = shortcode-string
    function jg_id_column_content( $column, $id ) {
      if( get_post_type( $post_id ) == 'et_pb_layout') {
        if( 'jg_id' == $column ) {
          echo '<a id="myButton',$id, '" name="myButton',$id, '" class="myButtonClass">[showmodule id="', $id, '"]</a>';
        }
      }
    }

The Javascript for copying the text to the clipboard was created according to the stackoverflow.com post 'Click button copy to clipboard using jQuery'. Thanks for the helpful comments.

JohnGalt
  • 37
  • 6
  • this is what i'm referring to, add another column for the shortcode :) add another column and the contents for that column would be to create the shortcode for each row, anyways nice job – Kevin Sep 17 '17 at 05:10
  • We have had a misunderstanding there. I already had the column in there but just couldn't mark and copy the text as the "Post Types Order"-plugin was overlaying it. That's why I was just looking for a means to add a custom command. As I am not a Wordpress expert It took me two days of reading (time well spent) to come up with a plugin that works well. Now I want learn how to upload a plugin so that the community can make use of it, too. – JohnGalt Sep 17 '17 at 09:14