403Webshell
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/post/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /webdata/gohomesh.com/wp-content/plugins/anything-order-by-terms/modules/post/class.php
<?php

/**
 * Post order.
 *
 * @since 1.0
 */
class Anything_Order_Post extends Anything_Order_Base {

	/**
	 * @var string Current term slug
	 *
	 * @since 1.2.1
	 */
	protected $term;

	/**
	 * Constructor.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		parent::__construct( array(
			'pagenow'       => 'edit',
			'objectnow'     => 'typenow',
			'inline_editor' => 'inlineEditPost',
			'query_var'     => 'post_type',
		) );

		add_action( 'parse_tax_query', array( $this, 'parse_tax_query' ), 20 );
	}

	/**
     * Fires after taxonomy-related query vars have been parsed.
	 * Hook: add hook for modify orderby clause on admin screen and the public site. Add different hook based on current term.
	 * Filters `posts_...` will not work if query args has 'suppress_filters' param.
	 *
	 * @since 1.3.6
	 * @see WP_Query::parse_tax_query()
	 *
	 * @param WP_Query $q The WP_Query instance.
	 */
	public function parse_tax_query( $q ) {

		$this->term = $this->get_current_term( $q );

		// Run if not term in query
		add_filter( 'posts_orderby', array( $this, 'posts_orderby' ) );

		// Run if term in query
		add_filter( 'posts_fields', array( $this, 'posts_fields' ) );
		add_filter( 'posts_join', array( $this, 'posts_join' ) );
		add_filter( 'posts_orderby', array( $this, 'posts_orderby_term' ) );


	}

	/**
	 * Hook: Modify order by clause for not tax page (for example shop page or listing all product in admin).
	 *
	 * @since 1.0.0
	 * @see WP_Query::get_posts()
	 *
	 * @param string $orderby Order by clause.
	 *
	 * @return string
	 */
	public function posts_orderby( $orderby ) {
		global $wpdb;
		if ( $this->do_order()
		     && ! $this->term
		     && false === strpos( $orderby, 'menu_order' )
		) {
			$orderby = "$wpdb->posts.menu_order ASC,$orderby";
		}

		return $orderby;
	}

	/**
	 * Hook: Modify select clause.
	 *
	 * @since 1.0.0
	 * @see WP_Query::get_posts()
	 *
	 * @param string $fields Selected post fields.
	 *
	 * @return string
	 */
	public function posts_fields( $fields ) {
		if ( $this->do_order() && $this->term ) {
			$fields .= ', CAST(m1.meta_value AS UNSIGNED) AS post_order_int';
		}

		return $fields;
	}

	/**
	 * Hook: Modify join clause.
	 *
	 * @since 1.0.0
	 * @see WP_Query::get_posts()
	 *
	 * @param string $join Joined tables.
	 *
	 * @return string
	 */
	public function posts_join( $join ) {
		global $wpdb;

		if ( $this->do_order() && $this->term ) {

			$join .= " LEFT JOIN $wpdb->postmeta m1 ON
         ({$wpdb->posts}.ID = m1.post_id AND m1.meta_key = '_order_{$this->term}')";

		}

		return $join;
	}

	/**
	 * Hook: Modify orderby clause for tax page.
	 *
	 * @since 1.0.0
	 * @see WP_Query::get_posts()
	 *
	 * @param string $orderby Orderby clause.
	 *
	 * @return string
	 */
	public function posts_orderby_term( $orderby ) {

		if ( $this->do_order() && $this->term ) {
			$orderby = "$orderby,COALESCE(post_order_int, ~0) ASC";
		}

		return $orderby;
	}

	/**
	 * Capability for ordering.
	 *
	 * @since 1.0.0
	 */
	protected function cap() {
		$post_type_object = get_post_type_object( $GLOBALS[ $this->objectnow ] );

		if ( ! $post_type_object ) {
			wp_die( __( 'Invalid post type', 'any-order' ) );
		}

		return $post_type_object->cap->edit_others_posts;
	}

	/**
	 * Manage a column for ordering.
	 *
	 * @since 1.0.0
	 *
	 * @param object $screen Current screen.
	 */
	protected function manage_column( $screen ) {
		add_filter( "manage_{$screen->post_type}_posts_columns", array( $this, 'get_columns' ), 100 ); //Before custom post types columns as Woocommerce product
		add_action( "manage_{$screen->post_type}_posts_custom_column", array( $this, 'render_column' ), 10, 2 );
	}

	/**
	 * Hook: Render a column for ordering.
	 *
	 * @since 1.0.0
	 */
	public function render_column( $column_name, $post_id ) {

		if ( 'anything-order' == $column_name ) {

			$post       = get_post( $post_id );
			$post_order = $post->menu_order;

			echo $this->_render_column( $post_id, $post_order );
		}
	}

	/**
	 * 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.
	 *
	 * @return bool Set order or reset?
	 */
	protected function _update( $ids, $order, $objectnow, $term ) {
		global $wpdb;
		if ( empty( $ids ) ) {
			if ( empty( $term ) ) {
				$wpdb->update(
					$wpdb->posts, array( 'menu_order' => 0 ), array( 'post_type' => $objectnow )
				);
			} else {
				delete_post_meta_by_key( "_order_$term" );
			}

			return false;
		} else {
			if ( empty( $term ) ) {
				foreach ( $ids as $id ) {
					if ( 0 < $id ) {
						$wpdb->update(
							$wpdb->posts, array( 'menu_order' => $order ++ ), array( 'ID' => $id )
						);
					}
				}
			} else {
				foreach ( $ids as $id ) {
					if ( 0 < $id ) {
						update_post_meta( $id, "_order_$term", $order ++ );
					}
				}
			}
		}

		return true;
	}

}

new Anything_Order_Post();

Youez - 2016 - github.com/yon3zu
LinuXploit