| Server IP : 39.106.62.82 / Your IP : 216.73.217.128 Web Server : nginx/1.14.1 System : Linux iz2ze1m0zmp2dk5c3j5ap5z 3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020 x86_64 User : www ( 1000) PHP Version : 7.4.33 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 MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /webdata/gohomesh.com/wp-content/plugins/anything-order-by-terms/modules/base/ |
Upload File : |
<?php
/**
* Base class.
* @since 1.0
*/
abstract class Anything_Order_Base
{
/**
* ID or name of this class.
* @since 1.0.0
* @var string
*/
protected $name = '';
/**
* Page now (not include '.php').
* @since 1.0.0
* @var string
*/
protected $pagenow = '';
/**
* Global variable name of current screen object.
*
* @since 1.0.0
*
* @var string
*/
protected $objectnow = '';
/**
* Name of the inline editor.
*
* @since 1.0.0
*
* @var string
*/
protected $inline_editor = '';
/**
* Query variable.
*
* @since 1.0.0
*
* @var string
*/
protected $query_var = '';
/**
* Error object.
*
* @since 1.0.0
*
* @var WP_Error
*/
protected $error = null;
/**
* Option value in admin selects bulk actions
*
* @since 1.3.0
*
* @var string
*/
protected $bulk_option_value = 'reset_order';
/**
* Constructor.
*
* @since 1.0.0
*/
protected function __construct($args = array())
{
$class = get_class($this);
$keys = array_keys(get_class_vars($class));
foreach ($keys as $key) {
if (isset($args[ $key ])) {
$this->$key = $args[ $key ];
}
}
$this->name = str_replace('Anything_Order_', '', $class);
if (!empty($this->pagenow)) {
add_action("admin_print_styles-{$this->pagenow}.php", array($this, 'admin_print_styles'));
add_action("admin_print_scripts-{$this->pagenow}.php", array($this, 'admin_print_scripts'));
}
add_action('admin_init', array($this, 'set_current_screen'));
add_action('current_screen', array($this, 'current_screen'));
add_action("wp_ajax_Anything_Order/update/{$this->name}", array($this, 'update'));
}
/**
* Order enable on front or on admin page unset order set via $_GET var.
*
* @since 1.2.0
*
* @return bool Is enable ordering?
*/
protected function do_order() {
return apply_filters("Anything_Order/do_order/{$this->name}",
!is_admin()
|| (is_admin()
&& !isset($_GET['orderby'])
)
);
}
/**
* Get an ID for the class.
*
* @since 1.0.0
*
* @return string
*/
protected function get_id($suffix = '')
{
$id = strtolower(get_class($this));
if (!empty($suffix)) {
$id .= "_$suffix";
}
return $id;
}
/**
* Hook: Set current screen.
*
* @since 1.0.0
*/
public function set_current_screen()
{
if (defined('DOING_AJAX') && isset($_POST['screen_id'])) {
convert_to_screen($_POST['screen_id'])->set_current_screen();
}
}
/**
* Hook: Add hooks depend on current screen.
*
* @since 1.0.0
*
* @param object $screen Current screen.
*/
public function current_screen($screen)
{
if (!apply_filters("Anything_Order/do_order/{$this->name}", true)) {
return;
}
if (get_current_screen()->base != $this->pagenow) {
return;
}
if (!current_user_can(apply_filters("Anything_Order/cap/{$this->name}", $this->cap(), $screen))) {
return;
}
$this->manage_column($screen);
$this->bulk_actions($screen);
}
/**
* Capability for ordering.
*
* @since 1.0.0
*/
abstract protected function cap();
/**
* Manage a column for ordering.
*
* @since 1.0.0
*
* @param object $screen Current screen.
*/
abstract protected function manage_column($screen);
/**
* Filter bulk actions
*
* @since 1.3.1
*
* @param $screen \WP_Screen
*/
protected function bulk_actions($screen) {
add_filter( "bulk_actions-{$screen->id}", array($this, 'add_reset_action') );
}
/**
* Add Reset Order action
*
* @since 1.3.1
*
* @param $actions array
*
* @return array
*/
public function add_reset_action($actions) {
$actions[$this->bulk_option_value] = esc_html__('Reset Order', 'any-order');
return $actions;
}
/**
* Hook: Prepend a column for ordering to columns.
*
* @since 1.0.0
*/
public function get_columns($columns)
{
$title = sprintf(
'<a href="%1$s">'.
'<span class="dashicons dashicons-sort"></span>'.
'</a>'.
'<span class="title">%2$s</span>',
esc_url($this->get_url()),
esc_html__('Order', 'any-order')
);
return array('anything-order' => $title) + $columns;
}
/**
* Retirive HTML for a column.
*
* @since 1.0.0
*/
protected function _render_column( $id, $order)
{
return sprintf(
'<span class="hidden anything-order-id">%1$s</span>'.
'<span class="hidden anything-order-order">%2$s</span>',
absint( $id ),
absint( $order )
);
}
/**
* Retrieve the url of an admin page.
*
* @since 1.0.0
*/
protected function get_url()
{
return add_query_arg($this->query_var, $GLOBALS[$this->objectnow], admin_url("{$this->pagenow}.php"));
}
/**
* Retrieve term on admin or front page from WP_Tax_Query.
*
* @since 1.1.6
*
* @param $q WP_Query Current or global instance.
*
* @see WP_Tax_Query
* @see $wp_query
*
* @return string Term on admin or front page.
*/
protected function get_current_term( $q = null) {
global $wp_query;
$term_slug = '';
$q = !is_null( $q ) ? $q : $wp_query;
if($q->tax_query!='') {
foreach ( $q->tax_query->queries as $key => $tax_query ) {
if ( 'relation' === $key ) {
continue;
}
$taxonomy = $tax_query['taxonomy'];
$taxonomy_object = get_taxonomy( $taxonomy );
// Only if term have ui. Skip language taxonomy from Polylang or product visibility from Woocommerce.
if ( ! $taxonomy_object || ! $taxonomy_object->show_ui ) {
continue;
}
//We cannot define order if query more than one terms
if ( '' !== $term_slug || count( $tax_query['terms'] ) > 1 ) {
return '';
}
// Need term slug, not term id
if ( 'term_id' === $tax_query['field'] ) {
$term_id = $tax_query['terms'][0];
$term = get_term( $term_id, $taxonomy );
$term_slug = $term->slug;
} else {
$term_slug = $tax_query['terms'][0];
}
}
}
return $term_slug;
}
/**
* Hook: Enqueue styles.
*
* @since 1.0.0
*/
public function admin_print_styles()
{
wp_enqueue_style($this->get_id('style'), plugin_dir_url(__FILE__).'style.css', array(), false, 'all');
}
/**
* Hook: Enqueue scripts.
*
* @since 1.0.0
*/
public function admin_print_scripts()
{
global $wp_query;
wp_enqueue_script($this->get_id('script'), plugin_dir_url(__FILE__).'script.js', array('jquery-ui-sortable'), false, true);
$params = apply_filters("Anything_Order/ajax_params/{$this->name}", array(
'_ajax_nonce' => wp_create_nonce("Anything_Order/update/{$this->name}"),
'action' => "Anything_Order/update/{$this->name}",
'inline' => $this->inline_editor,
'objectnow' => $GLOBALS[$this->objectnow],
'term' => $this->get_current_term(),
'bulk_option_value' => $this->bulk_option_value
));
$texts = array(
'confirmReset' => __("Are you sure you want to reset order?\n 'Cancel' to stop, 'OK' to reset.", 'any-order'),
);
wp_localize_script($this->get_id('script'), 'anythingOrder', array(
'params' => $params,
'texts' => $texts,
));
}
/**
* Hook: Update order.
*
* @since 1.0.0
*/
final public function update()
{
check_ajax_referer("Anything_Order/update/{$this->name}");
$this->error = new WP_Error();
$ids = isset($_POST['ids'])
? array_filter(array_map('intval', explode(',', $_POST['ids'])))
: array();
$order = isset($_POST['order']) ? intval($_POST['order']) : 0;
$objectnow = isset($_POST['objectnow']) ? $_POST['objectnow'] : '';
$term = isset($_POST['term']) ? $_POST['term'] : '';
if (!$order) {
$this->error->add(
'invalid_order',
__('Invalid ordering number is posted.', 'any-order')
);
}
$msgs = $this->error->get_error_messages();
if (empty($msgs)) {
$redirect = $this->_update($ids, $order, $objectnow, $term)
? ''
: $this->get_url();
echo json_encode(array(
'status' => 'success',
'redirect' => $redirect
));
} else {
echo json_encode(array(
'status' => 'error',
'message' => implode('<br>', $msgs),
));
}
wp_die();
}
/**
* Update order.
*
* @since 1.0.0
*
* @param array $ids Object IDs to update order.
* @param int $order The number to start ordering.
* @param string $objectnow Current screen object name.
* @param string $term Edited term on admin screen.
* @param string $taxonomy Edited taxonomy on admin screen.
*
* @return bool True if updated. False if reset.
*/
abstract protected function _update($ids, $order, $objectnow, $term);
}