Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
}
],
"require": {
"johnbillion/extended-cpts": "^4.0",
"php": "^7.4|^8.0",
"johnbillion/extended-cpts": "^5.0",
"wpackagist-plugin/cmb2": "2.11.*",
"wpackagist-plugin/elasticpress": "^4.0 | ^5.0",
"yahnis-elsts/plugin-update-checker": "^5.0"
Expand Down
585 changes: 344 additions & 241 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions config/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
'file' => 'cmb2/init.php',
],
[
'type' => 'class',
'type' => 'function',
'label' => '<a href="https://github.com/johnbillion/extended-cpts" target="_blank">Extended CPT library</a>',
'name' => 'Extended_CPT',
'name' => 'register_extended_post_type'
]
],

Expand Down
2 changes: 1 addition & 1 deletion config/seopress_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
'_seopress_social_twitter_img_width',
'_seopress_social_twitter_img_height',
]
];
];
2 changes: 1 addition & 1 deletion src/Base/Admin/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function filterPostLink(string $link, WP_Post $post, bool $leavename, $sa
*/
public function filterPreviewLink(string $link, WP_Post $post): string
{
if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) {
if ($post->post_type !== 'openpub-item' || ! $this->plugin->settings->isPortalSlugValid()) {
return $link;
}

Expand Down
16 changes: 15 additions & 1 deletion src/Base/Foundation/DependencyChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function failed(): bool
case 'plugin':
$this->checkPlugin($dependency);
break;
case 'function':
$this->checkFunction($dependency);
break;
}
}

Expand Down Expand Up @@ -116,14 +119,25 @@ private function checkPlugin(array $dependency): void
}
}

/**
* Checks if required function exists.
*/
private function checkFunction(array $dependency): void
{
if (! function_exists($dependency['name'])) {
$this->markFailed($dependency, __('Function does not exist:', 'openpub-base') . ' <b>' . $dependency['name'] . '</b>');
}
}


/**
* Checks the installed version of the plugin.
*/
private function checkVersion(array $dependency): bool
{
try {
$file = file_get_contents(WP_PLUGIN_DIR . '/' . $dependency['file']);
} catch(\Exception $e) {
} catch (\Exception $e) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Base/Metabox/Commands/AbstractConvert.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function execute(): void
foreach ($this->flattenArray($holder) as $item) {
try {
$this->convert($item);
} catch(Exception $e) {
} catch (Exception $e) {
WP_CLI::error(sprintf('Something went wrong with converting item [%s]. Error: %s', $item->post_title, $e->getMessage()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Metabox/Commands/ConvertExpirationDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function convertDateToTimeStamp(WP_Post $item): ?int

try {
$object = new DateTime($date);
} catch(Exception $e) {
} catch (Exception $e) {
return null;
}

Expand Down
110 changes: 55 additions & 55 deletions src/Base/PostType/PostTypeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,69 @@

class PostTypeServiceProvider extends ServiceProvider
{
/**
* The array of posttype definitions from the config
*/
protected array $configPostTypes = [];
/**
* The array of posttype definitions from the config
*/
protected array $configPostTypes = [];

public function register()
{
$this->plugin->loader->addAction('init', $this, 'registerPostTypes');
$this->plugin->loader->addAction('pre_get_posts', $this, 'orderByPublishedDate');
$this->plugin->loader->addAction('wp_insert_post_data', $this, 'fillPostName', 10, 4);
}
public function register()
{
$this->plugin->loader->addAction('init', $this, 'registerPostTypes');
$this->plugin->loader->addAction('pre_get_posts', $this, 'orderByPublishedDate');
$this->plugin->loader->addAction('wp_insert_post_data', $this, 'fillPostName', 10, 4);
}

/**
* Add default order.
*/
public function orderByPublishedDate(WP_Query $query): void
{
if (! is_admin()) {
return;
}
/**
* Add default order.
*/
public function orderByPublishedDate(WP_Query $query): void
{
if (! is_admin()) {
return;
}

if (! $query->is_main_query() || 'openpub-item' != $query->get('post_type')) {
return;
}
if (! $query->is_main_query() || 'openpub-item' != $query->get('post_type')) {
return;
}

if (isset($_GET['orderby'])) {
return;
}
if (isset($_GET['orderby'])) {
return;
}

$query->set('orderby', 'post_date');
$query->set('order', 'DESC');
}
$query->set('orderby', 'post_date');
$query->set('order', 'DESC');
}

/**
* Register custom posttypes.
*/
public function registerPostTypes(): void
{
if (function_exists('register_extended_post_type')) {
$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));
foreach ($this->configPostTypes as $postTypeName => $postType) {
// Examples of registering post types: http://johnbillion.com/extended-cpts/
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
}
}
}
/**
* Register custom posttypes.
*/
public function registerPostTypes(): void
{
if (function_exists('register_extended_post_type')) {
$this->configPostTypes = apply_filters('owc/openpub-base/before-register-posttypes', $this->plugin->config->get('posttypes'));
foreach ($this->configPostTypes as $postTypeName => $postType) {
// Examples of registering post types: http://johnbillion.com/extended-cpts/
register_extended_post_type($postTypeName, $postType['args'], $postType['names']);
}
}
}

/**
* Always fill the post_name when empty and a post is not published.
* When previewing an openpub-item the post_name needs to be present, which is set by default when the post is published.
*/
public function fillPostName(array $post, array $postarr, array $unsanitizedPostarr, bool $update): array
{
if ('openpub-item' !== $post['post_type'] || empty($postarr['ID']) || 'publish' === $post['post_status']) {
return $post;
}
/**
* Always fill the post_name when empty and a post is not published.
* When previewing an openpub-item the post_name needs to be present, which is set by default when the post is published.
*/
public function fillPostName(array $post, array $postarr, array $unsanitizedPostarr, bool $update): array
{
if ('openpub-item' !== $post['post_type'] || empty($postarr['ID']) || 'publish' === $post['post_status']) {
return $post;
}

if (! empty($postarr['post_name'])) {
return $post;
}
if (! empty($postarr['post_name'])) {
return $post;
}

$post['post_name'] = \sanitize_title($post['post_title']);
$post['post_name'] = \sanitize_title($post['post_title']);

return $post;
}
return $post;
}
}
4 changes: 2 additions & 2 deletions src/Base/RestAPI/Controllers/ThemeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace OWC\OpenPub\Base\RestAPI\Controllers;

use WP_Post;
use OWC\OpenPub\Base\Repositories\Theme;
use WP_Error;
use WP_Post;
use WP_REST_Request;
use OWC\OpenPub\Base\Repositories\Theme;

class ThemeController extends BaseController
{
Expand Down
2 changes: 1 addition & 1 deletion src/Base/Settings/SettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function register()

public function registerMissingNumberField($field, $escapedValue, $objectID, $objectType, $fieldTypeObject): void
{
echo $fieldTypeObject->input(array( 'type' => 'number' ));
echo $fieldTypeObject->input([ 'type' => 'number' ]);
}

public function registerSettingsPages(): void
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/Base/RestAPI/Controllers/ItemControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use OWC\OpenPub\Base\Foundation\Loader;
use OWC\OpenPub\Base\Foundation\Plugin;
use OWC\OpenPub\Base\RestAPI\Controllers\ItemController;
use OWC\OpenPub\Base\RestAPI\ItemFields\FeaturedImageField;
use OWC\OpenPub\Tests\TestCase;
use WP_Mock;
use WP_Post;
Expand Down Expand Up @@ -44,9 +43,9 @@ public function it_transforms_a_wp_object_to_array()
$post->post_date = '01-01-2021';
$post->post_name = 'test-test';

$itemController = m::mock(ItemController::class)->makePartial();
$itemController = m::mock(ItemController::class)->makePartial();

$itemController->shouldReceive('getImageUrl')->andReturn([]);
$itemController->shouldReceive('getImageUrl')->andReturn([]);

WP_Mock::userFunction('get_the_post_thumbnail_url', [
'args' => [
Expand All @@ -63,7 +62,7 @@ public function it_transforms_a_wp_object_to_array()
'excerpt' => 'Test excerpt',
'date' => '01-01-2021',
'thumbnail_url' => 'url-to-image',
'image' => [],
'image' => [],
'slug' => 'test-test',
];

Expand Down
Loading