Skip to content

Commit

Permalink
Whitespace standardisation
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmuswinter committed Jun 10, 2021
1 parent fdc6222 commit daa873e
Show file tree
Hide file tree
Showing 14 changed files with 1,773 additions and 1,659 deletions.
74 changes: 39 additions & 35 deletions oowp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,62 @@
AdminUtils::customiseAdmin();

if (!function_exists('unregister_post_type')) {
function unregister_post_type($post_type)
{
global $wp_post_types;
if (isset($wp_post_types[$post_type])) {
unset($wp_post_types[$post_type]);
function unregister_post_type($post_type)
{
global $wp_post_types;
if (isset($wp_post_types[$post_type])) {
unset($wp_post_types[$post_type]);

add_action('admin_menu', function () use ($post_type) {
remove_menu_page('edit.php' . ($post_type == 'post' ? "" : "?post_type=$post_type"));
}, $post_type);
return true;
}
return false;
}
add_action('admin_menu', function () use ($post_type) {
remove_menu_page('edit.php' . ($post_type == 'post' ? "" : "?post_type=$post_type"));
}, $post_type);
return true;
}
return false;
}
}


/**
* Reverse the effects of register_taxonomy()
*
* @package WordPress
* @subpackage Taxonomy
* @since 3.0
* @uses $wp_taxonomies Modifies taxonomy object
*
* @param string $taxonomy Name of taxonomy object
* @param array|string $object_type Name of the object type
* @return bool True if successful, false if not
* @uses $wp_taxonomies Modifies taxonomy object
*
* @package WordPress
* @subpackage Taxonomy
* @since 3.0
*/

if(!function_exists('unregister_taxonomy')){
function unregister_taxonomy($taxonomy, $object_type = ''){
global $wp_taxonomies;
if (!function_exists('unregister_taxonomy')) {
function unregister_taxonomy($taxonomy, $object_type = '')
{
global $wp_taxonomies;

if (!isset($wp_taxonomies[$taxonomy]))
return false;
if (!isset($wp_taxonomies[$taxonomy])) {
return false;
}

if (!empty($object_type)) {
$i = array_search($object_type, $wp_taxonomies[$taxonomy]->object_type);
if (!empty($object_type)) {
$i = array_search($object_type, $wp_taxonomies[$taxonomy]->object_type);

if (false !== $i)
unset($wp_taxonomies[$taxonomy]->object_type[$i]);
if (false !== $i) {
unset($wp_taxonomies[$taxonomy]->object_type[$i]);
}

if (empty($wp_taxonomies[$taxonomy]->object_type))
unset($wp_taxonomies[$taxonomy]);
} else {
unset($wp_taxonomies[$taxonomy]);
}
if (empty($wp_taxonomies[$taxonomy]->object_type)) {
unset($wp_taxonomies[$taxonomy]);
}
} else {
unset($wp_taxonomies[$taxonomy]);
}

return true;
}
return true;
}
}

add_shortcode(ListPostsShortcode::NAME, function($params, $content) {
add_shortcode(ListPostsShortcode::NAME, function ($params, $content) {
ListPostsShortcode::apply($params, $content);
});
});
237 changes: 125 additions & 112 deletions src/OowpQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,116 +7,129 @@
class OowpQuery extends \WP_Query implements \IteratorAggregate, \ArrayAccess, \Countable
{

/**
* @var WordpressPost[]
*/
var $posts;

/**
* @param string|array $query
*/
function __construct($query = '') {
global $wp_post_types;

$defaults = array(
'posts_per_page' => -1,
'post_status' => 'publish'
);
$query = wp_parse_args($query, $defaults);

// if there is no post type, or the post type is singular and isn't valid, replace it with 'any'
if (!isset($query['post_type']) || (!is_array($query['post_type']) && !array_key_exists($query['post_type'], $wp_post_types))) {
$query['post_type'] = 'any';
}

parent::__construct($query);

if ($this->query_vars['error']) {
die('Query error ' . $this->query_vars['error']);
}
}

/* Interfaces */

public function getIterator() {
return new \ArrayIterator($this->posts);
}

public function offsetExists($offset) {
return isset($this->posts[$offset]);
}

public function offsetGet($offset) {
return $this->posts[$offset];
}

public function offsetSet($offset, $value) {
$this->posts[$offset] = $value;
}

public function offsetUnset($offset) {
unset($this->posts[$offset]);
}

public function count() {
return count($this->posts);
}

/**
* Stores $this as the global $wp_query, executes the passed-in WP function, then reverts $wp_query
* @return mixed
*/
protected function callGlobalQuery() {
global $wp_query;
$args = func_get_args();
$function = array_shift($args);
$oldQuery = $wp_query;
$wp_query = $this;
$returnVal = call_user_func_array($function, $args);
$wp_query = $oldQuery;
return $returnVal;
}

/**
* Prints the prev/next links for this query
* @param string $sep
* @param string $preLabel
* @param string $nextLabel
*/
public function postsNavLink($sep = '', $preLabel = '', $nextLabel = '') {
$this->callGlobalQuery('posts_nav_link', $sep, $preLabel, $nextLabel);
}

public function queryVars() {
return new QueryVars($this->query_vars);
}

public function sortByIds($ids) {
$indexes = array_flip($ids);
usort($this->posts, function($a, $b) use ($indexes) {
$aIndex = $indexes[$a->ID];
$bIndex = $indexes[$b->ID];
return $aIndex < $bIndex ? -1 : 1;
});
}

/**
* Convert WP_Post objects to WordpressPost
* @return WordpressPost[]
*/
public function &get_posts() {
parent::get_posts();

foreach ($this->posts as $i => $post) {
$this->posts[$i] = WordpressPost::createWordpressPost($post);
}

if (count($this->posts)) {
$this->post = $this->posts[0];
$this->queried_object = $this->post;
$this->queried_object_id = $this->post->ID;
}

return $this->posts;
}
/**
* @var WordpressPost[]
*/
var $posts;

/**
* @param string|array $query
*/
function __construct($query = '')
{
global $wp_post_types;

$defaults = array(
'posts_per_page' => -1,
'post_status' => 'publish'
);
$query = wp_parse_args($query, $defaults);

// if there is no post type, or the post type is singular and isn't valid, replace it with 'any'
if (!isset($query['post_type']) || (!is_array($query['post_type']) && !array_key_exists($query['post_type'],
$wp_post_types))) {
$query['post_type'] = 'any';
}

parent::__construct($query);

if ($this->query_vars['error']) {
die('Query error ' . $this->query_vars['error']);
}
}

/* Interfaces */

public function getIterator()
{
return new \ArrayIterator($this->posts);
}

public function offsetExists($offset)
{
return isset($this->posts[$offset]);
}

public function offsetGet($offset)
{
return $this->posts[$offset];
}

public function offsetSet($offset, $value)
{
$this->posts[$offset] = $value;
}

public function offsetUnset($offset)
{
unset($this->posts[$offset]);
}

public function count()
{
return count($this->posts);
}

/**
* Stores $this as the global $wp_query, executes the passed-in WP function, then reverts $wp_query
* @return mixed
*/
protected function callGlobalQuery()
{
global $wp_query;
$args = func_get_args();
$function = array_shift($args);
$oldQuery = $wp_query;
$wp_query = $this;
$returnVal = call_user_func_array($function, $args);
$wp_query = $oldQuery;
return $returnVal;
}

/**
* Prints the prev/next links for this query
* @param string $sep
* @param string $preLabel
* @param string $nextLabel
*/
public function postsNavLink($sep = '', $preLabel = '', $nextLabel = '')
{
$this->callGlobalQuery('posts_nav_link', $sep, $preLabel, $nextLabel);
}

public function queryVars()
{
return new QueryVars($this->query_vars);
}

public function sortByIds($ids)
{
$indexes = array_flip($ids);
usort($this->posts, function ($a, $b) use ($indexes) {
$aIndex = $indexes[$a->ID];
$bIndex = $indexes[$b->ID];
return $aIndex < $bIndex ? -1 : 1;
});
}

/**
* Convert WP_Post objects to WordpressPost
* @return WordpressPost[]
*/
public function &get_posts()
{
parent::get_posts();

foreach ($this->posts as $i => $post) {
$this->posts[$i] = WordpressPost::createWordpressPost($post);
}

if (count($this->posts)) {
$this->post = $this->posts[0];
$this->queried_object = $this->post;
$this->queried_object_id = $this->post->ID;
}

return $this->posts;
}
}
Loading

0 comments on commit daa873e

Please sign in to comment.