/** * @covers WPGlobus_Utils::is_function_in_backtrace */ public static function test_is_function_in_backtrace() { self::assertTrue(WPGlobus_Utils::is_function_in_backtrace(__FUNCTION__)); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace(__FUNCTION__ . 'trailer')); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace('no-such-function')); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace(null)); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace(3.14)); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace(new stdClass())); self::assertFalse(WPGlobus_Utils::is_function_in_backtrace(array('a', 278, new stdClass()))); /** * One level deeper */ self::_unit_test_for_backtrace(); }
/** * Filter @see wp_get_object_terms() * @scope admin * @scope front * * @param string[]|stdClass[] $terms An array of terms for the given object or objects. * * @return array */ public static function filter__wp_get_object_terms(array $terms) { /** * @internal * Do not need to check for is_wp_error($terms), * because the WP_Error is returned by wp_get_object_terms() before applying filter. */ if (!count($terms)) { return $terms; } /** * Don't filter term names when saving or publishing posts * @todo Check this before add_filter and not here * @todo Describe exactly how to check this visually, and is possible - write the acceptance test */ if (is_admin() && WPGlobus_WP::is_pagenow('post.php') && (!empty($_POST['save']) || !empty($_POST['publish']))) { return $terms; } /** * Don't filter term names for trash and un-trash single post * @see we check post.php page instead of edit.php because redirect */ if (is_admin() && WPGlobus_WP::is_pagenow('post.php') && isset($_GET['action']) && ('trash' == $_GET['action'] || 'untrash' == $_GET['action'])) { return $terms; } /** * Don't filter term names bulk trash and untrash posts */ if (is_admin() && WPGlobus_WP::is_pagenow('edit.php') && isset($_GET['action']) && ('trash' == $_GET['action'] || 'untrash' == $_GET['action'])) { return $terms; } /** * Don't filter term names for bulk edit post from edit.php page */ if (is_admin() && WPGlobus_Utils::is_function_in_backtrace('bulk_edit_posts')) { return $terms; } /** * Don't filter term names for inline-save ajax action from edit.php page * @see wp_ajax_inline_save * ...except when the same AJAX refreshes the table row @see WP_Posts_List_Table::single_row * - * @qa At the "All posts" admin page, do Quick Edit on any post. After update, categories and tags * must not show multilingual strings with delimiters. * @qa At Quick Edit, enter an existing tag. After save, check if there is no additional tag * on the "Tags" page. If a new tag is created then the "is tag exists" check was checking * only a single language representation of the tag, while there is a multilingual tag in the DB. */ if (WPGlobus_WP::is_http_post_action('inline-save') && WPGlobus_WP::is_pagenow('admin-ajax.php')) { if (!WPGlobus_Utils::is_function_in_backtrace('single_row')) { return $terms; } } /** * Don't filter term names for heartbeat autosave */ if (WPGlobus_WP::is_http_post_action('heartbeat') && WPGlobus_WP::is_pagenow('admin-ajax.php') && !empty($_POST['data']['wp_autosave'])) { return $terms; } /** * Don't filter term name at time generate checklist categories in metabox */ if (is_admin() && WPGlobus_WP::is_pagenow('post.php') && empty($_POST) && WPGlobus_Utils::is_function_in_backtrace('wp_terms_checklist')) { return $terms; } foreach ($terms as &$_term) { WPGlobus_Core::translate_term($_term, WPGlobus::Config()->language); } unset($_term); reset($terms); return $terms; }