Possible to mash these 2 wp plugins together?

14 replies
Posting this here for someone who may be up for a little php challenge

Here's the situation.

I have a lot of stuff to sell, but approval needs to come from 3 sources for each item.

I'm posting the stuff on a wordpress site.

I found a couple of nifty plugins, but not sure if I can get them to co-operate.

1. Admin Columns

So this plugin allows me to specify what columns are currently being displayed when I click on "posts":



2. Multiple Approvals

This plugin forces approval by a set # of people before the post is published.
It is seen when you are actually in editing the post itself.



I'm looking to have the posts page enabled to:
1. show thumbnail of item (check)
2. Show title of item (check)
3. show approval status - with user able to use that function on the listed posts page without having to click into the edit post ( )
4. Show dates (check)

That approvals plugin was reported by some as not working - but seems to be working just fine for me.



Here is what it looks like when I want to add a new column to the posts list:



Not sure which plugin (if both) needs some code or something added so maybe this might work.


The desired result is that when the other 2 log in to approve, they can quickly do it on the posts page without having to kick into each post to do it.

Like I said, it's going to be a LOT of things to get approved in big chunks, and the other 2 just need a simple way to scan and either approve of the items or disapprove.

If you have an alternative suggestion on how to handle this, I'm all ears as well.

The 2 plugins being used are open source.

I found a 3rd - which added more options to that dropdown menu above - mentioning "plugins" but my preferred plugin is not showing in the selection list.

That 3rd plugin is called "custom admin columns"

Here are the plugin locations:
https://wordpress.org/plugins/codepress-admin-columns/
https://wordpress.org/plugins/multiple-approvals/
https://wordpress.org/plugins/custom-admin-column/

Anyone up for a challenge?
#mash #plugins
  • Profile picture of the author majick
    without looking at the plugins in detail (just about to go to bed sorry) you might be able to use the Custom Field option shown in the dropdown and simply find out which meta field the approvals are stored in? that is a start anyway, depends how the approvals are stored I guess...
    {{ DiscussionBoard.errors[10403761].message }}
    • Profile picture of the author Jill Carpenter
      Originally Posted by majick View Post

      without looking at the plugins in detail (just about to go to bed sorry) you might be able to use the Custom Field option shown in the dropdown and simply find out which meta field the approvals are stored in? that is a start anyway, depends how the approvals are stored I guess...
      I started to tinker there, but didn't understand really how to try to customize it.

      Sweet dreams to you though!

      I have to venture out at about 2pm today and won't be back to computer access until later.

      Not sure where you live, but I'm looking at a very late night working on some things, so maybe I'll see you in about 10 hours from now.

      It's wide open for anyone wanting to tackle.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[10403788].message }}
  • Profile picture of the author majick
    i'd say no need for the columns plugin for this, just the approvals one...
    add this to a PHP file and put it in /wp-content/my-plugins/

    // add the column
    function add_approvals_column( $columns ) {
    return array_merge( $columns, array( 'approvals' => 'Approvals' ) );
    }
    add_filter( 'manage_posts_columns' , 'add_approvals_column' );

    // add the metabox to the column
    function display_posts_approvals( $column, $post_id ) {
    if ($column == 'approvals') {
    // for no crash if approvals plugin deactivated
    if (function_exists('mait_display_post_meta_box')) {
    // retrieve the post object based on ID
    $post = get_post($post_id);
    // insert the approvals metabox for post
    mait_display_post_meta_box($post);
    // hide the save/submit button in the metabox?
    // hacky but this button is really for the edit screen
    echo "<style>#mait_save_button {display:none;}</style>";
    }
    }
    }
    add_action( 'manage_posts_custom_column' , 'display_posts_approvals', 10, 2 );

    // must add the js to the edit.php list screen too...
    add_action( 'load-edit.php', 'mait_insertjs' );

    ...that should do it, I haven't tested it but hopefully saves fine via ajax..?
    {{ DiscussionBoard.errors[10404608].message }}
    • Profile picture of the author Jill Carpenter
      Not sure if I added this in the right place.

      I gave it it's own file name, and called it multiple-approvals-addon.php Tried sticking that directly in the plugins folder but nothing happened. Then stuck it in it's own folder within the plugins folder and nothing.

      Also tried sticking it directly in the plugin folder named multiple approvals.

      Not seeing any change.

      PHP Code:
       <?php 
      // add the column
      function add_approvals_column(  ) {
      return 
      array_merge( , array( 'approvals' => 'Approvals' ) );
      }
      add_filter'manage_posts_columns' 'add_approvals_column' );

      // add the metabox to the column
      function display_posts_approvals( ,  ) {
      if ( == 
      'approvals') {
      // for no crash if approvals plugin deactivated
      if (function_exists('mait_display_post_meta_box')) {
      // retrieve the post object based on ID
       
      get_post();
      // insert the approvals metabox for post
      mait_display_post_meta_box();
      // hide the save/submit button in the metabox?
      // hacky but this button is really for the edit screen
      echo "<style>#mait_save_button {display:none;}</style>";
      }
      }
      }
      add_action'manage_posts_custom_column' 'display_posts_approvals'10);

      // must add the js to the edit.php list screen too...
      add_action'load-edit.php''mait_insertjs' ); ?>
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[10405202].message }}
  • Profile picture of the author majick
    sorry there was a typo there damnit, you need to create the /wp-content/mu-plugins/ directory, (must-use plugins) as any php file there auto-loaded by wordpress with no questions asked.

    (the downside is if there is a typo in the code it could break the site so be prepared to debug.) note: the code quoted is not the same as original, make sure it hasn't gone screwy.

    either that or put it in it's own plugin directory eg. /wp-content/plugins/approvals-column/
    but if you do it that way you need to give the file a valid plugin header and activate it.
    {{ DiscussionBoard.errors[10408069].message }}
    • Profile picture of the author Jill Carpenter
      Going to try this again later this afternoon.

      I was also trying to research, and one suggestion was that this kind of code should go into the theme itself.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[10412356].message }}
      • Profile picture of the author Jill Carpenter
        OMG, so flippin close!

        The progress bar is showing. I am able to click it. But note the top one that I clicked:



        When I clicked to approve, it gave me that /3 which should have turned into a 1/3 and the blue on the progress bar should have moved.

        When I clicked it again to "unapprove" I was sent to a page "Whoops! Page Not Found"

        One other thing I noticed - this plugin relies on determining which user is logged in - which I'm not confident it's making that detection in it's current state.
        Signature

        "May I have ten thousand marbles, please?"

        {{ DiscussionBoard.errors[10412483].message }}
        • Profile picture of the author Jill Carpenter
          Oh, I tossed it into an MU folder.

          Just tried with the columns plugin deactivated, and there it did not kick me to the whoops page, but still not showing progress on the color bar or the #approved.

          Oh, and if I approve one, it's showing them all as approved.

          Edit - got kicked to a whoops page again after tinkering.
          Signature

          "May I have ten thousand marbles, please?"

          {{ DiscussionBoard.errors[10412490].message }}
          • Profile picture of the author Jill Carpenter
            Well, if I were to use this alongside "admin columns" I did find some additional template for creating a plugin: https://www.admincolumns.com/documen...w-column-type/

            Not sure if trying this will make things work more like they are supposed to or just muck it up more.

            With the fixes you gave me, the approvals plugin does show as a plugin option now when using admin columns. Just not sure if that will make it function the way it's supposed to should a new plugin be created with their template.

            Tried looking up the original plugin creator for approvals plugin but he doesn't give any direct contact information on his website.

            I may be back to finding another streamlined solution that can give me this functionality.
            Signature

            "May I have ten thousand marbles, please?"

            {{ DiscussionBoard.errors[10413763].message }}
  • Profile picture of the author majick
    so the reason it's not working yet is basically:

    1. the metabox has a single CSS id value, columns need multiple so probably classes.
    2. this is needed because the javascript launching the ajax needs to know which post is referenced, which can be determined from what is clicked...

    replacement metabox function with class ids base on post
    -> modified ajax.js javascript -> unmodified ajax call

    may have another play with it tomorrow, but yeah that's what needs to happen.
    {{ DiscussionBoard.errors[10416686].message }}
  • Profile picture of the author majick
    alrighty... try this for the mu-plugins php file:

    // add the column to the post list screen
    function add_approvals_column( $columns ) {
    return array_merge( $columns, array( 'approvals' => 'Approvals' ) );
    }
    add_filter( 'manage_posts_columns' , 'add_approvals_column' );

    // add alternative js to the edit.php list screen...
    add_action( 'load-edit.php', 'mait_insert_column_js' );
    function mait_insert_column_js() {
    global $current_user;
    $muplugins = WP_CONTENT_URL.'/mu-plugins/';
    wp_enqueue_script( 'mait_columns_ajax_js_handle', $muplugins.'approvals-column-ajax.js', array('jquery'), '', true );
    $protocol = isset( $_SERVER['HTTPS'] ) ? 'https://' : 'http://';
    $params = array(
    'ajaxurl' => admin_url( 'admin-ajax.php', $protocol ),
    'userid' => $current_user->ID
    );
    wp_localize_script( 'mait_columns_ajax_js_handle', 'mait_params', $params );
    }

    // add the metabox to the column
    function display_posts_approvals( $column, $post_id ) {
    if ($column == 'approvals') {
    // for no crash if approvals plugin deactivated
    if (function_exists('mait_display_post_meta_box')) {
    // retrieve the post object based on ID
    $post = get_post($post_id);
    // insert the column approvals metabox
    mait_display_column_meta_box($post);
    }
    }
    }
    add_action( 'manage_posts_custom_column' , 'display_posts_approvals', 10, 2 );

    // custom column metabox output
    function mait_display_column_meta_box($post) {

    global $current_user;
    $mait_nonce = wp_create_nonce( 'mait_nonce' );
    $approval_users = get_post_meta( $post->ID, 'mait_approval_user', false );
    $approval_status = get_post_meta( $post->ID, 'mait_approval_status', true );
    $options = get_option( 'mait_options' );
    $min = $options['min'];

    // add the post ID to the box
    echo '<div class="mait_approval_box" id="mait'.$post->ID.'">';

    $published = $approval_status == $min || $post->post_status == 'publish';
    $progress = $published ? 100 : ( $approval_status / $min ) * 100 + 1;
    if ($post->post_status == 'publish') {$min = $approval_status;}

    echo '<span class="mait_header mait'.$post->ID.'">Approvals</span>';
    echo ' ( <span class="mait_approval_number mait'.$post->ID.'">'.$approval_status.'</span> / '.$min.' )';
    echo '<div class="mait_progress_bar mait'.$post->ID.'" title="Click to toggle the approval list">';
    echo '<div style="width: '.$progress.'%;" class="mait_progress mait'.$post->ID.'">';
    if ( $published ) {echo 'Published';}
    echo '</div></div><div class="mait_approval_list mait'.$post->ID.'">';
    if (empty($approval_users)) {echo 'No one approved this post yet.';}
    else {echo mait_list_approval_users($approval_users);}
    echo '</div></div>';

    echo '<div class="mait_approval_buttons mait'.$post->ID.'">';
    if (!$published) {
    if (in_array($current_user->ID, $approval_users)) {
    echo '<div class="mait_remove_approval submitbox mait_options_bar mait'.$post->ID.'" id="mait'.$post->ID.'">';
    echo '<a class="submitdelete" href="'.$mait_nonce.'">Remove your approval</a></div>';
    }
    else {
    echo '<div class="mait_approve mait_options_bar mait'.$post->ID.'" id="mait'.$post->ID.'"><strong>';
    echo '<a href="'.$mait_nonce.'" class="button-primary">Approve</a></strong></div>';
    }
    }
    echo '</div>';
    }
    {{ DiscussionBoard.errors[10419307].message }}
  • Profile picture of the author majick
    then save this as approvals-column-ajax.js in mu-plugins folder:

    (function($){

    // use class instead of ID
    $('.mait_progress_bar').hover(
    function(){
    $(this).css({'opacity': '0.5', 'cursor':'pointer'});
    },
    function(){
    $(this).css({'opacity': '1', 'cursor':'default'});
    }
    );

    // use subclass instead of ID
    $('.mait_progress_bar').click(
    function(){
    $(this).find('.mait_approval_list').toggle();
    }
    );

    // removed postid data from here
    var data_approve = {
    action: 'mait_approve_post',
    userid: mait_params.userid,

    };
    var data_remove = {
    action: 'mait_remove_approval',
    userid: mait_params.userid
    };

    // callback functions
    function mait_remove_approval(){
    data_remove['nonce'] = $(this).find('a').attr('href');
    // set the post id based on the id of the element clicked
    var thispostid = $(this).attr('id').replace('mait','');
    data_remove['postid'] = thispostid;
    // use post id class from here on instead of single element ID
    $('.mait_options_bar.mait'+thispostid).html('');

    $.post( mait_params.ajaxurl, data_remove, function(response){
    var status = $(response).find('mait_remove_approval').attr('id' );

    if ( status == 1 ){
    var data = $(response).find('response_data').text();
    var status = $(response).find('status').text();
    var approvals = $(response).find('approvals').text();

    $('.mait_approval_number.mait'+thispostid).text(ap provals);
    $('.mait_approval_list.mait'+thispostid).html(data );
    $('.mait_options_bar.mait'+thispostid).replaceWith ('<div class="mait_approve mait_options_bar mait'+thispostid+'" id="mait'+thispostid+'"><strong><a href="'+data_remove['nonce']+'" class="button-primary">Approve</a></strong>');
    $('.mait_progress.mait'+thispostid).css('width',st atus+'%');
    $('.mait_approve.mait'+thispostid).click( mait_approve );
    }
    });
    return false;
    }

    function mait_approve(){
    data_approve['nonce'] = $(this).find('a').attr('href');
    // set the post id based on the id of the element clicked
    var thispostid = $(this).attr('id').replace('mait','');
    data_approve['postid'] = thispostid;
    // use post id class from here on instead of single element ID
    $('.mait_options_bar.mait'+thispostid).html('');

    $.post( mait_params.ajaxurl, data_approve, function(response){
    var status = $(response).find('mait_approve_post').attr('id');

    if ( status == 1 ){
    var data = $(response).find('response_data').text();
    var status = $(response).find('status').text();
    var approvals = $(response).find('approvals').text();

    $('.mait_approval_number.mait'+thispostid).text(ap provals);
    $('.mait_approval_list.mait'+thispostid).html(data );
    $('.mait_progress.mait'+thispostid).css('width',st atus+'%');

    if ( status == 100 ){
    $('#mait_progress.mait'+thispostid).text('Publishe d');
    }
    else{
    $('.mait_options_bar.mait'+thispostid).replaceWith ('<div class="mait_remove_approval submitbox mait_options_bar mait'+thispostid+'" id="mait'+thispostid+'"><a class="submitdelete" href="'+data_approve['nonce']+'">Remove your approval</a></div>');
    $('.mait_remove_approval').click( mait_remove_approval );
    }
    }
    });
    return false;
    }

    // add these callback functions to the button/link
    $('.mait_approve').click( mait_approve );
    $('.mait_remove_approval').click( mait_remove_approval );

    })(jQuery)
    {{ DiscussionBoard.errors[10419309].message }}
    • Profile picture of the author Jill Carpenter
      Will give it a try!

      Sorry I didn't see this earlier.

      Something wanky is going on with the pm box as of late.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[10442642].message }}
  • Profile picture of the author lordspace
    Wow. You folks are brave to co-write/edit WordPress plugins in a forum without proper formatting ... and possibly on a live site... that's brave.
    Signature

    Are you using WordPress? Have you tried qSandbox yet?

    {{ DiscussionBoard.errors[10448875].message }}

Trending Topics