$post->post_content empty while all other properties are correct

I’m trying to pull raw post content in order to identify if a particular shortcode is used, and if so, what its properties are. All of the properties of my $post object return what I expect except for post_content, which seems to give me an empty value. I’ve tried removing all markup from the body in order to avoid any potential pre-processing, but even then I get nothing. Here’s how I try for the content;

    $content_post = get_post($post->ID, OBJECT, 'edit');
    $content = $content_post->post_content;

I got the same result using

    $content_post = get_post($post->ID, OBJECT, 'raw');

This being my first WP project, I’m hoping I missed something simple…

Go to Source
Author: GoetzOnline

Minify HTML with voku / HtmlMin?

I want use voku/HtmlMin in wordpress functions.php, i install composerr in theme folder and i use code:

class WP_HTML_Compression

{
    // Settings
    protected $compress_css = true;
    protected $compress_js = true;
    protected $info_comment = true;
    protected $remove_comments = true;

    // Variables
    protected $html;

    public function __construct($html) 
    {

        if (!empty($html)) {
         $this->parseHTML($html);
        }
    }

    public function __toString()
    {
        return $this->html;
    }

    protected function bottomComment($raw, $compressed)
    {
        $raw = strlen($raw);
        $compressed = strlen($compressed);

        $savings = ($raw-$compressed) / $raw * 100;

        $savings = round($savings, 2);

        return '<!--HTML compressed, size saved '.$savings.'%. From '.$raw.' bytes, now '.$compressed.' bytes-->';
    }

    protected function minifyHTML($html)
    {
      require('vendor/autoload.php');
    $htmlMin = new vokuhelperHtmlMin();

        return $htmlMin->doRemoveComments->doSortCssClassNames()->doSortHtmlAttributes()->minify($html);

      
    $htmlMin = vokuhelperHtmlMin;
        $htmlMin = new HtmlMin();
      
    }

    public function parseHTML($html)
    {
        $this->html = $this->minifyHTML($html);

        if ($this->info_comment) {
            $this->html .= "n" . $this->bottomComment($html, $this->html);
        }
    }

    protected function removeWhiteSpace($str)
    {
        $str = str_replace("t", ' ', $str);
        $str = str_replace("n",  '', $str);
        $str = str_replace("r",  '', $str);

        while (stristr($str, '  ')) {
            $str = str_replace('  ', ' ', $str);
        }

        return $str;
    }
}

function wp_html_compression_finish($html) {
    return new WP_HTML_Compression($html);
}

function wp_html_compression_start() {
    ob_start('wp_html_compression_finish');
}
add_action('get_header', 'wp_html_compression_start');

but it’s not work. How add voku/htmlmin correct?

Go to Source
Author: johm

How Can I Create a Friendly Slug for a Dynamic Page?

I built a dynamic page template that pulls biography information from a MySQL table.

The page works fine but the URL is ugly.

Officer-Biography/?ID=1

I have a set of canonical slugs that I want to use for each officer.

for example, Officer-Firstname-Lastname

I’ve tried both htacess and add_rewrite_rule and both give me 404.

example: add_rewrite_rule('Officer-Erich-Abberger', 'Officer-Biography/?ID=1', 'top');

What am I missing?

Go to Source
Author: jpollar

How to reorder hooks output order of Seconday menu and Product search (Storefront theme)

I would like to center Product search on about the same line with Site logo and align right on the same line the secondary menu on site https://prettify.ru (I’m not advertising or something… I put a link just to be more concrete on the subject. Hopely it is not against rules).
The default hooks’ output for Storefront theme is like this

  1. Site Branding (logo e.t.c.)
  2. Secondary menu
  3. Product search
  4. Primary navigation menu

e.t.c.

I was trying to play with CSS with that set up but it seems pretty hard for me (I’m a noob, ha ha) to center Product Search for all resolutions with that hooks order.
My Idea how to do habdle this is to change output priorities: show Product search right after Site Branding and then Show Secondary menu. Only after that play with CSS rules/styling.

What I’m see at storefront-template-hooks.php is

add_action( 'storefront_header', 'storefront_header_container', 0 );
add_action( 'storefront_header', 'storefront_skip_links', 5 );
add_action( 'storefront_header', 'storefront_site_branding', 20 );
add_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
add_action( 'storefront_header', 'storefront_header_container_close', 41 );
add_action( 'storefront_header', 'storefront_primary_navigation_wrapper', 42 );
add_action( 'storefront_header', 'storefront_primary_navigation', 50 );
add_action( 'storefront_header', 'storefront_primary_navigation_wrapper_close', 68 );

No call for search function. My logic was like that: find output for product search and set priority higher than storefront_secondary_navigation: let say 25. But I can not find where the search priority is set up. I’m using AJAX Search for WooCommerce plugin and that makes things to be a bit more complicated, he he.
Can someone please suggest how to reorder items in header?
Will it work for my target: center cearch and align secondary menu right?

Go to Source
Author: 0LEg

Naming convention for a function which checks whether scroll required or not?

There is function which checks whether scroll required or not by doing some DOM height width calucation before enabling the scroll in the webpage.

I named the function as checkScrollNeeded. Is there a better name or any naming conventions to refer.

Go to Source
Author: Sivashanmugam Kannan

How to change users avatar with specific e-mail addresses

How to set user avatar (website.com/wp-content/anonimus-avatar.png) for e-mails:

anonimus_0@anonimus.com
anonimus_1@anonimus.com
anonimus_2@anonimus.com
anonimus_3@anonimus.com
anonimus_4@anonimus.com
anonimus_5@anonimus.com
anonimus_6@anonimus.com
anonimus_7@anonimus.com
anonimus_8@anonimus.com
anonimus_9@anonimus.com
anonimus_10@anonimus.com
anonimus_11@anonimus.com
......
anonimus_57@anonimus.com
anonimus_58@anonimus.com
anonimus_59@anonimus.com

Go to Source
Author: UserUser-name

Create a Postgresql trigger that updates column with PK of other table

Hello and thanks for taking the time in advance to look at my question. This is my first try at using triggers and functions in PostgreSQL (using DBeaver) and I appreciate your feedback.

I’d like to update a column (village_id) every time a new row is entered or updated with the primary key value of a different table (which is not connected as a foreign key directly). See below for an outline of my tables and trigger + function.

Unfortunately, after using the code below I received an error each time I was entering a new row with information. I used an UPDATE statement, but I also considered using an insert into statement, but wasn’t sure what is more preferable. Thank you in advance.

  CREATE TABLE register_table
(register_id integer CONSTRAINT register_id_pk PRIMARY KEY,
  village_id integer NOT NULL
);
      CREATE TABLE er_table
(er_id integer CONSTRAINT er_id_pk PRIMARY KEY,
  register_id integer NOT NULL,
  village_id integer NOT NULL
);

CREATE OR REPLACE FUNCTION update_village_id_column()
    RETURNS trigger AS
  $BODY$
BEGIN
UPDATE schema_example.er_table
SET  village_id = register_table.village_id
from schema_example.register_table
WHERE (schema_example.register_id = new.register_id);

RETURN new; 
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

CREATE TRIGGER update_village_id
AFTER INSERT OR UPDATE
ON schema_example.er_table
FOR EACH ROW
EXECUTE PROCEDURE update_village_id_column();

Go to Source
Author: PGerrits

How would I go about replacing this function in my child theme located in inc/template-tags.php

How would I replace this function that lies inside inc/template-tags.php in my parent theme

function theme_navigation() {
?>
        
        <div id="theme-nav-container">
            <nav id="site-navigation" class="main-navigation">
                <?php wp_nav_menu( array('theme_location' => 'theme-studios-primary', 'menu_class' => 'sf-menu', 'fallback_cb' => false, 'walker'  => new theme ) ); ?><div class="clearfix-pro"></div>
            </nav>
            <div class="clearfix-pro"></div>
        </div>
        
        <!-- close #theme-nav-container -->
        
        
<?php
}

There is no add action that it is hooked on to, there is no check to see if the function already exists. How would I replace it without touching the parent theme. I have removed much of the code in the function for brevity but I think it still makes sense.

Thanks ahead of time

Go to Source
Author: Anders Kitson

Child theme overirde template-tags in a theme built on underscores in inc/template-tags

I’ve read this post and I don’t think this question is a duplicate because I have a specific question that has not been answered.

My parent theme is using the following to require a template tag php file

require get_template_directory() . '/inc/template-tags.php';

Is it possible to overide this in my child theme, If I place the same code in my functions.php and place the folder and file the same in my child theme folder I get a error saying

 Fatal error: Cannot redeclare progression_studios_category_transient_flusher() (previously declared in /home/anders/Local Sites/site/app/public/wp-content/themes/vayvo-progression-child/inc/template-tags.php:401) in /home/anders/Local Sites/site/app/public/wp-content/themes/vayvo-progression/inc/template-tags.php on line 401

Is it possible to work around this.

Thanks ahead of time.

Go to Source
Author: Anders Kitson