| Server IP : 38.190.208.107 / Your IP : 216.73.216.146 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : www ( 1000) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.11/wp-content/themes/woodmart/inc/admin/modules/dashboard/ |
Upload File : |
<?php
/**
* Class to create a display button and switch the status of publication.
*
* @package woodmart
*/
namespace XTS\Admin\Modules\Dashboard;
class Status_Button {
/**
* Post type name to which the button will be added.
*
* @var string $post_type Post type name.
*/
private $post_type = '';
/**
* The column name.
*
* @var string $column_name The column name.
*/
private $column_name = '';
/**
* The position of the column with the button.
*
* @var int $column_position The position of the column with the button.
*/
private $column_position = '';
/**
* Constructor.
*
* @param string $post_type Post type name.
* @param int $column_position The position of the column with the button.
*/
public function __construct( $post_type, $column_position = 2 ) {
$this->post_type = $post_type;
$this->column_name = $this->post_type . '_status';
$this->column_position = $column_position;
// Status switcher column in post type page.
add_action( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'admin_columns_titles' ) );
add_action( 'manage_' . $this->post_type . '_posts_custom_column', array( $this, 'admin_columns_content' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'wp_ajax_wd_change_post_status', array( $this, 'change_status_action' ) );
}
/**
* Columns header.
*
* @param array $posts_columns Columns.
*
* @return array
*/
public function admin_columns_titles( $posts_columns ) {
return array_slice( $posts_columns, 0, $this->column_position, true ) + array(
$this->column_name => esc_html__( 'Active', 'woodmart' ),
) + array_slice( $posts_columns, $this->column_position, null, true );
}
/**
* Columns content.
*
* @param string $column_name Column name.
* @param int $post_id Post id.
*/
public function admin_columns_content( $column_name, $post_id ) {
if ( $this->column_name === $column_name ) {
$this->get_template( $post_id );
}
}
/**
* Enqueue admin scripts.
*
* @return void
*/
public function enqueue_scripts() {
if ( get_post_type() !== $this->post_type ) {
return;
}
wp_enqueue_script( 'wd-status-button', WOODMART_ASSETS . '/js/statusButton.js', array(), WOODMART_VERSION, true );
}
/**
* Get status button template.
*
* @param int $post_id Post id.
*
* @return string|void
*/
public function get_template( $post_id ) {
$doing_ajax = function_exists( 'is_ajax' ) ? \is_ajax() : ( defined( 'DOING_AJAX' ) && DOING_AJAX );
if ( $doing_ajax ) {
ob_start();
}
$status = get_post_status( $post_id );
$nonce = wp_create_nonce( 'wd_change_status_' . $post_id );
include get_parent_theme_file_path( WOODMART_FRAMEWORK . '/admin/modules/dashboard/templates/status-button.php' );
if ( $doing_ajax ) {
return ob_get_clean();
}
}
/**
* Change status action.
*/
public function change_status_action() {
$post_id = woodmart_clean( $_POST['id'] ); // phpcs:ignore
$status = woodmart_clean( $_POST['status'] ); // phpcs:ignore
check_ajax_referer( 'wd_change_status_' . $post_id, 'security' );
do_action( 'woodmart_change_post_status' );
wp_update_post(
array(
'ID' => $post_id,
'post_status' => $status,
)
);
wp_send_json(
array(
'new_html' => $this->get_template( $post_id ),
)
);
}
}