2017-07-26 14:57:52 +03:00
|
|
|
<?php
|
|
|
|
|
namespace um\admin\core;
|
|
|
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
|
|
|
|
|
2018-03-26 01:27:46 +03:00
|
|
|
if ( ! class_exists( 'um\admin\core\Admin_Columns' ) ) {
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Class Admin_Columns
|
|
|
|
|
* @package um\admin\core
|
|
|
|
|
*/
|
|
|
|
|
class Admin_Columns {
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Admin_Columns constructor.
|
|
|
|
|
*/
|
|
|
|
|
function __construct() {
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
add_filter( 'manage_edit-um_form_columns', array( &$this, 'manage_edit_um_form_columns' ) );
|
|
|
|
|
add_action( 'manage_um_form_posts_custom_column', array( &$this, 'manage_um_form_posts_custom_column' ), 10, 3 );
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
add_filter( 'manage_edit-um_directory_columns', array( &$this, 'manage_edit_um_directory_columns' ) );
|
|
|
|
|
add_action( 'manage_um_directory_posts_custom_column', array( &$this, 'manage_um_directory_posts_custom_column' ), 10, 3 );
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
add_filter( 'post_row_actions', array( &$this, 'post_row_actions' ), 99, 2 );
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
// Add a post display state for special UM pages.
|
|
|
|
|
add_filter( 'display_post_states', array( &$this, 'add_display_post_states' ), 10, 2 );
|
2018-04-03 12:53:41 +03:00
|
|
|
|
|
|
|
|
add_filter( 'post_row_actions', array( &$this, 'remove_bulk_actions_um_form_inline' ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This will remove the "Edit" bulk action, which is actually quick edit.
|
|
|
|
|
*
|
|
|
|
|
* @param array $actions
|
|
|
|
|
*
|
|
|
|
|
* @return array;
|
|
|
|
|
*/
|
|
|
|
|
function remove_bulk_actions_um_form_inline( $actions ) {
|
|
|
|
|
if ( UM()->admin()->is_plugin_post_type() ) {
|
|
|
|
|
unset( $actions['inline hide-if-no-js'] );
|
|
|
|
|
return $actions;
|
|
|
|
|
}
|
|
|
|
|
return $actions;
|
2018-03-16 09:37:19 +02:00
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Custom row actions
|
|
|
|
|
*
|
|
|
|
|
* @param array $actions
|
|
|
|
|
* @param \WP_Post $post
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
function post_row_actions( $actions, $post ) {
|
|
|
|
|
//check for your post type
|
|
|
|
|
if ( $post->post_type == "um_form" ) {
|
|
|
|
|
$actions['um_duplicate'] = '<a href="' . $this->duplicate_uri( $post->ID ) . '">' . __( 'Duplicate', 'ultimate-member' ) . '</a>';
|
|
|
|
|
}
|
|
|
|
|
return $actions;
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Duplicate a form
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function duplicate_uri( $id ) {
|
|
|
|
|
$url = add_query_arg('um_adm_action', 'duplicate_form', admin_url('edit.php?post_type=um_form') );
|
|
|
|
|
$url = add_query_arg('post_id', $id, $url);
|
|
|
|
|
return $url;
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Custom columns for Form
|
|
|
|
|
*
|
|
|
|
|
* @param array $columns
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function manage_edit_um_form_columns( $columns ) {
|
|
|
|
|
$new_columns['cb'] = '<input type="checkbox" />';
|
|
|
|
|
$new_columns['title'] = __( 'Title', 'ulitmatemember' );
|
|
|
|
|
$new_columns['id'] = __('ID', 'ulitmatemember' );
|
|
|
|
|
$new_columns['mode'] = __( 'Type', 'ulitmatemember' );
|
|
|
|
|
$new_columns['shortcode'] = __( 'Shortcode', 'ulitmatemember' );
|
|
|
|
|
$new_columns['date'] = __( 'Date', 'ulitmatemember' );
|
|
|
|
|
|
|
|
|
|
return $new_columns;
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Custom columns for Directory
|
|
|
|
|
*
|
|
|
|
|
* @param array $columns
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function manage_edit_um_directory_columns( $columns ) {
|
|
|
|
|
$new_columns['cb'] = '<input type="checkbox" />';
|
|
|
|
|
$new_columns['title'] = __( 'Title', 'ultimate-member' );
|
|
|
|
|
$new_columns['id'] = __( 'ID', 'ultimate-member' );
|
|
|
|
|
$new_columns['shortcode'] = __( 'Shortcode', 'ultimate-member' );
|
|
|
|
|
$new_columns['date'] = __( 'Date', 'ultimate-member' );
|
|
|
|
|
|
|
|
|
|
return $new_columns;
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Display custom columns for Form
|
|
|
|
|
*
|
|
|
|
|
* @param string $column_name
|
|
|
|
|
* @param int $id
|
|
|
|
|
*/
|
|
|
|
|
function manage_um_form_posts_custom_column( $column_name, $id ) {
|
|
|
|
|
switch ( $column_name ) {
|
|
|
|
|
case 'id':
|
|
|
|
|
echo '<span class="um-admin-number">'.$id.'</span>';
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'shortcode':
|
|
|
|
|
echo UM()->shortcodes()->get_shortcode( $id );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'mode':
|
|
|
|
|
$mode = UM()->query()->get_attr( 'mode', $id );
|
|
|
|
|
echo UM()->form()->display_form_type( $mode, $id );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
|
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
/**
|
|
|
|
|
* Display cusom columns for Directory
|
|
|
|
|
*
|
|
|
|
|
* @param string $column_name
|
|
|
|
|
* @param int $id
|
|
|
|
|
*/
|
|
|
|
|
function manage_um_directory_posts_custom_column( $column_name, $id ) {
|
|
|
|
|
switch ( $column_name ) {
|
|
|
|
|
case 'id':
|
|
|
|
|
echo '<span class="um-admin-number">'.$id.'</span>';
|
|
|
|
|
break;
|
|
|
|
|
case 'shortcode':
|
|
|
|
|
echo UM()->shortcodes()->get_shortcode( $id );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
|
2017-12-11 09:53:38 +02:00
|
|
|
|
2017-11-30 18:03:58 +02:00
|
|
|
/**
|
2018-03-16 09:37:19 +02:00
|
|
|
* Add a post display state for special UM pages in the page list table.
|
|
|
|
|
*
|
|
|
|
|
* @param array $post_states An array of post display states.
|
|
|
|
|
* @param \WP_Post $post The current post object.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
2017-12-11 09:53:38 +02:00
|
|
|
public function add_display_post_states( $post_states, $post ) {
|
2017-11-30 18:03:58 +02:00
|
|
|
|
2017-12-11 09:53:38 +02:00
|
|
|
foreach ( UM()->config()->core_pages as $page_key => $page_value ) {
|
2018-03-02 09:55:49 +02:00
|
|
|
$page_id = UM()->options()->get( UM()->options()->get_core_page_id( $page_key ) );
|
2017-11-30 18:03:58 +02:00
|
|
|
|
2017-12-11 09:53:38 +02:00
|
|
|
if ( $page_id == $post->ID ) {
|
2018-03-19 16:31:49 +02:00
|
|
|
$post_states[ 'um_core_page_' . $page_key ] = sprintf( 'UM %s', $page_value['title'] );
|
2017-12-11 09:53:38 +02:00
|
|
|
}
|
|
|
|
|
}
|
2017-11-30 18:03:58 +02:00
|
|
|
|
2017-12-11 09:53:38 +02:00
|
|
|
return $post_states;
|
|
|
|
|
}
|
2017-11-30 18:03:58 +02:00
|
|
|
|
2018-03-16 09:37:19 +02:00
|
|
|
}
|
2017-07-26 14:57:52 +03:00
|
|
|
}
|