Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Remove unused post function #473

Merged
merged 1 commit into from
Sep 8, 2023
Merged
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
168 changes: 0 additions & 168 deletions source/php/Helper/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,174 +132,6 @@ public static function isArchive()
return false;
}

/**
* Prepare post object before sending to view
* Appends useful variables for views (generic).
*
* @param object $post WP_Post object
*
* @return object $post Transformed WP_Post object
*/
public static function preparePostObject($post) {
$post = self::complementObject($post);
$post = \Modularity\Helper\FormatObject::camelCase($post);
return $post;
}

/**
* Add post data on post object
*
* @param object $postObject The post object
* @param object $appendFields Data to append on object
*
* @return object $postObject The post object, with appended data
*/
public static function complementObject(
$postObject,
$appendFields = array(
'excerpt',
'post_content_filtered',
'post_title_filtered',
'permalink',
'terms'
)
) {

//Check that a post object is entered
if (!is_a($postObject, 'WP_Post')) {
return $postObject;
throw new WP_Error("Complement object must recive a WP_Post class");
}

//More? Less?
$appendFields = apply_filters('Modularity/Helper/Post/complementPostObject', $appendFields);

//Generate excerpt
if (in_array('excerpt', $appendFields)) {
if (empty($postObject->post_excerpt)) {

//Create excerpt if not defined by editor
$postObject->excerpt = wp_trim_words(
$postObject->post_content,
apply_filters('Modularity/Helper/Post/ExcerptLenght', 55),
apply_filters('Modularity/Helper/Post/MoreTag', "...")
);

//Create excerpt if not defined by editor
$postObject->excerpt_short = wp_trim_words(
$postObject->post_content,
apply_filters('Modularity/Helper/Post/ExcerptLenghtShort', 20),
apply_filters('Modularity/Helper/Post/MoreTag', "...")
);

//No content in post
if (empty($postObject->excerpt)) {
$postObject->excerpt = '<span class="undefined-content">' . __("Item is missing content", 'municipio') . "</span>";
}
} else {
$postObject->excerpt_short = wp_trim_words(
$postObject->content,
apply_filters('Modularity/Helper/Post/ExcerptLenghtShort', 20),
apply_filters('Modularity/Helper/Post/MoreTag', "...")
);
}
}

//Get permalink
if (in_array('permalink', $appendFields)) {
$postObject->permalink = get_permalink($postObject);
}

//Get filtered content
if (in_array('post_content_filtered', $appendFields)) {
//Parse lead
$parts = explode("<!--more-->", $postObject->post_content);

if(is_array($parts) && count($parts) > 1) {

//Remove the now broken more block
foreach ($parts as &$part) {
$part = str_replace('<!-- wp:more -->', '', $part);
$part = str_replace('<!-- /wp:more -->', '', $part);
}

$excerpt = self::createLeadElement(array_shift($parts));
$content = self::removeEmptyPTag(implode(PHP_EOL, $parts));

} else {
$excerpt = "";
$content = self::removeEmptyPTag($postObject->post_content);
}

//Replace builtin css classes to our own
$postObject->post_content_filtered = $excerpt . str_replace(
[
'wp-caption',
'c-image-text',
'wp-image-',
'alignleft',
'alignright',
'alignnone',
'aligncenter',

//Old inline transition button
'btn-theme-first',
'btn-theme-second',
'btn-theme-third',
'btn-theme-fourth',
'btn-theme-fifth',

//Gutenberg columns
'wp-block-columns',

//Gutenberg block image
'wp-block-image',
'<figcaption>'
],
[
'c-image',
'c-image__caption',
'c-image__image wp-image-',
'u-float--left@sm u-float--left@md u-float--left@lg u-float--left@xl u-margin__y--2 u-margin__right--2@sm u-margin__right--2@md u-margin__right--2@lg u-margin__right--2@xl u-width--100@xs',
'u-float--right@sm u-float--right@md u-float--right@lg u-float--right@xl u-margin__y--2 u-margin__left--2@sm u-margin__left--2@md u-margin__left--2@lg u-margin__left--2@xl u-width--100@xs',
'',
'u-margin__x--auto',

//Old inline transition button
'c-button c-button__filled c-button__filled--primary c-button--md',
'c-button c-button__filled c-button__filled--secondary c-button--md',
'c-button c-button__filled c-button__filled--secondary c-button--md',
'c-button c-button__filled c-button__filled--secondary c-button--md',
'c-button c-button__filled c-button__filled--secondary c-button--md',

//Gutenberg columns
'o-grid o-grid--no-margin@md',

//Gutenberg block image
'c-image',
'<figcaption class="c-image__caption">'
],
apply_filters('the_content', $content)
);
}

//Get filtered post title
if (in_array('post_title_filtered', $appendFields)) {
$postObject->post_title_filtered = apply_filters('the_title', $postObject->post_title);
}

//Get post tumbnail image
$postObject->thumbnail = self::getFeaturedImage($postObject->ID, [400, 225]);

//Append post terms
if (in_array('terms', $appendFields)) {
$postObject->terms = self::getPostTerms($postObject->ID);
$postObject->termsUnlinked = self::getPostTerms($postObject->ID, false);
}

return $postObject;
}

/**
* Remove empty ptags from string
*
Expand Down
Loading