{ if ( isset( $value->$index_key ) ) { $newlist[ $value->$index_key ] = $value->$field; } else { $newlist[] = $value->$field; } } else { if ( isset( $value[ $index_key ] ) ) { $newlist[ $value[ $index_key ] ] = $value[ $field ]; } else { $newlist[] = $value[ $field ]; } } } $this->output = $newlist; return $this->output; } /** * Sorts the list, based on one or more orderby arguments. * * @since 4.7.0 * * @param string|array $orderby Optional. Either the field name to order by or an array * of multiple orderby fields as $orderby => $order. * @param string $order Optional. Either 'ASC' or 'DESC'. Only used if $orderby * is a string. * @param bool $preserve_keys Optional. Whether to preserve keys. Default false. * @return array The sorted array. */ public function sort( $orderby = array(), $order = 'ASC', $preserve_keys = false ) { if ( empty( $orderby ) ) { return $this->output; } if ( is_string( $orderby ) ) { $orderby = array( $orderby => $order ); } foreach ( $orderby as $field => $direction ) { $orderby[ $field ] = 'DESC' === strtoupper( $direction ) ? 'DESC' : 'ASC'; } $this->orderby = $orderby; if ( $preserve_keys ) { uasort( $this->output, array( $this, 'sort_callback' ) ); } else { usort( $this->output, array( $this, 'sort_callback' ) ); } $this->orderby = array(); return $this->output; } /** * Callback to sort the list by specific fields. * * @since 4.7.0 * * @see WP_List_Util::sort() * * @param object|array $a One object to compare. * @param object|array $b The other object to compare. * @return int 0 if both objects equal. -1 if second object should come first, 1 otherwise. */ private function sort_callback( $a, $b ) { if ( empty( $this->orderby ) ) { return 0; } $a = (array) $a; $b = (array) $b; foreach ( $this->orderby as $field => $direction ) { if ( ! isset( $a[ $field ] ) || ! isset( $b[ $field ] ) ) { continue; } if ( $a[ $field ] == $b[ $field ] ) { continue; } $results = 'DESC' === $direction ? array( 1, -1 ) : array( -1, 1 ); if ( is_numeric( $a[ $field ] ) && is_numeric( $b[ $field ] ) ) { return ( $a[ $field ] < $b[ $field ] ) ? $results[0] : $results[1]; } return 0 > strcmp( $a[ $field ], $b[ $field ] ) ? $results[0] : $results[1]; } return 0; } } al variable */ public function get_wp_taxonomies() { global $wp_taxonomies; return $wp_taxonomies; } /** * Wrapper for get_category_link function * * @param int $category_id * * @return string */ public function get_category_link( $category_id ) { return get_category_link( $category_id ); } /** * Wrapper for is_wp_error function * * @param mixed $thing * * @return bool */ public function is_wp_error( $thing ) { return is_wp_error( $thing ); } /** * @param int $limit * @param bool $provide_object * @param bool $ignore_args * * @return array */ public function get_backtrace( $limit = 0, $provide_object = false, $ignore_args = true ) { $options = false; if ( version_compare( $this->phpversion(), '5.3.6' ) < 0 ) { // Before 5.3.6, the only values recognized are TRUE or FALSE, // which are the same as setting or not setting the DEBUG_BACKTRACE_PROVIDE_OBJECT option respectively. $options = $provide_object; } else { // As of 5.3.6, 'options' parameter is a bitmask for the following options: if ( $provide_object ) { $options |= DEBUG_BACKTRACE_PROVIDE_OBJECT; } if ( $ignore_args ) { // phpcs:disable PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound -- It has a version check $options |= DEBUG_BACKTRACE_IGNORE_ARGS; // phpcs:enable PHPCompatibility.Constants.NewConstants.debug_backtrace_ignore_argsFound } } // phpcs:disable PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection -- It has a version check // phpcs:disable PHPCompatibility.FunctionUse.NewFunctionParameters.debug_backtrace_limitFound -- It has a version check if ( version_compare( $this->phpversion(), '5.4.0' ) >= 0 ) { $debug_backtrace = debug_backtrace( $options, $limit ); // add one item to include the current frame } elseif ( version_compare( $this->phpversion(), '5.2.4' ) >= 0 ) { // @link https://core.trac.wordpress.org/ticket/20953 $debug_backtrace = debug_backtrace(); } else { $debug_backtrace = debug_backtrace( $options ); } // phpcs:enable PHPCompatibility.FunctionUse.NewFunctionParameters.debug_backtrace_limitFound // phpcs:enable PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection // Remove the current frame if ( $debug_backtrace ) { array_shift( $debug_backtrace ); } return $debug_backtrace; } /** * @return WP_Filesystem_Direct */ public function get_wp_filesystem_direct() { global $wp_filesystem; require_once ABSPATH . 'wp-admin/includes/file.php'; /** * We need to make sure that `WP_Filesystem` has been called * at least once so that some constants are defined with * default values. */ if ( ! $wp_filesystem ) { WP_Filesystem(); } require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; return new WP_Filesystem_Direct( null ); } /** * @return WPML_Notices */ public function get_admin_notices() { global $wpml_admin_notices; if ( ! $wpml_admin_notices ) { $wpml_admin_notices = new WPML_Notices( new WPML_Notice_Render() ); $wpml_admin_notices->init_hooks(); } return $wpml_admin_notices; } /** * @param Twig_LoaderInterface $loader * @param array $environment_args * * @return Twig_Environment */ public function get_twig_environment( $loader, $environment_args ) { return new Twig_Environment( $loader, $environment_args ); } /** * @param array $template_paths * * @return Twig_Loader_Filesystem|\WPML\Core\Twig_LoaderInterface */ public function get_twig_loader_filesystem( $template_paths ) { return new Twig_Loader_Filesystem( $template_paths ); } /** * @return \WPML\Core\Twig_Loader_String|\WPML\Core\Twig_LoaderInterface */ public function get_twig_loader_string() { return new Twig_Loader_String(); } public function is_a_REST_request() { return defined( 'REST_REQUEST' ) && REST_REQUEST; } }