custom post types – update_post_meta() inside “save_post” hook doesn’t save to database – only through REST API

I have a function that is being called whenever a woocommerce product is published (through the save_post hook).

This function uploads a few images, attaches them to the current post being saved (using update_post_meta with the _product_image_gallery key and set_post_thumbnail function).

If I create and publish a product through the wp admin dashboard, this works great, no issues.

If I create a product through the REST API, the images get uploaded (so my function on the save_post hook is being called), but the image ID’s do not get saved in the database.

The update_post_meta function on the rest API call does return a meta ID, however searching in the wp_postmeta table, this ID is not to be found..

I feel like the REST API is somehow overwriting/deleting my update_post_meta call, and am curious if anyone else has ever ran into the same issue or has any workaround for this.

request hook for oEmbeds? – WordPress Development Stack Exchange

When I try to oEmbed my own links, or try to oEmbed links from my own site on other sites, the oEmbed fails with the unhelpful message “This content can not be included”.

When I check the headers of my pages, they contain an oEmbed reference, like so:

https://{{my site}}/wp-json/oembed/1.0/embed?url={{my page's encoded URL}}

When I visit this URL, I get this:

{"code":"oembed_invalid_url","message":"Not Found","data":{"status":404}}

For returning the correct content in the frontend, in order to avoid conflicting permalinks between different content types (which have the same permalink structure), I hook into the request hook, like so:

add_filter( 'request', 'my_parse_request' );

I guess that, when requesting the oEmbed for a particular link, this request hook is not fired, and the requested article can not be found by the oEmbed.

So, I suppose my question is, how do have ‘my_parse_request’ also run when requesting the oEmbed for an article on my site?

javascript – React Hook useEffect has a missing dependency: ‘storeInfo’

Estou tentando usar useEffect para uma simples função, mas da erro. Ele não tá atualizando a pagina e salvando a requisição que faço com a função loadAll no useState. Quando carrego a página o resultado de storeInfo é o null que é o valor default e não o valor atualizado. Da o aviso de dependência ( React Hook useEffect has a missing dependency: ‘storeInfo’. Either include it or remove the dependency array react-hooks/exhaustive-deps )

  const (storeInfo, setStoreInfo) = useState(null);

  useEffect(()=>{
    const loadAll = async () => {
      let chosenInfo = await Tmdb.getStoreById(635302);
      setStoreInfo(chosenInfo);
    }
    console.log(storeInfo)
    loadAll();
  }, ());

Se eu coloco storeInfo no array de dependência como pede fica em loop infinito.

  const (storeInfo, setStoreInfo) = useState(null);

  useEffect(()=>{
    const loadAll = async () => {
      let chosenInfo = await Tmdb.getStoreById(635302);
      setStoreInfo(chosenInfo);
    }
    console.log(storeInfo)
    loadAll();
  }, (storeInfo));

Não sei mais o que fazer 🙁
Se alguém conseguir me ajudar, ficarei grato!

vue.js – Vue :src Error in mounted hook: “TypeError: Cannot read property ‘0’ of undefined”

I get an error when trying to get the name of the image, wonder what product.images(0) gives an array , and then product.images(0)․name gives an error

enter image description here

<template>
  <div class="container mt-5" v-if="products">
    <div class="row products">
      <div v-for="(product,index) in products" :key="product.id" class="product col-12 mx-auto">
        <div class="product_image">
           <img :src="https://stackoverflow.com/product.images(0).image" alt="">
        </div>
        <div class="product_info">
          <h4 class="product_title">{{product.name}}</h4>
          <h3 class="product_price">${{product.price}}</h3>
        </div>
      </div>
    </div>
  </div>
</template>

.

export default {
   data(){
      return {
         name: "Products"
      }
   },
  props:{
     products:Array
  },
  computed:{
     baseUrl(){
       return this.$store.getters.getBaseUrl
     }
  },
}

php – How to use a custom hook

The problem is the order of execution. The order things run matters.

For your code to function, it would require either add_action to implement time travel several microseconds into the past so that it can add the hook before it ran, or it would require do_action to implement precognition so that it knows about add_action calls in the future that have not happened yet.

By putting your add_action call in home.php or other templates that occur after the header.php runs, you are telling WordPress to execute code when a hook fires that has already fired.

It is the equivalent to arriving at an airport and trying to board a flight that has already left.

You need to add the actions before using it.

A useful mental model is to think of actions as events. When you specify add_action of add_filter it is the same as saying “from now on, when this action runs, do this”.

This is also why you do not see themes add filters and actions inside template files. These go in plugins and functions.php because those files are loaded earlier.

filters – Where to hook to force WP to create compressed copy of uploaded image even if its small

I want to write a filter function and need help figuring out where it would be best to hook in or if there is any possibility at all.

My problem:

I am utilizing the jpeg_quality hook along with max_srcset_image_width hook and some custom intermediate sizes for optimization purposes.

The problem is that WP only makes a copy for an image only if a registered image size is lower then the original.

Say that my site has registered image sizes: 600×600, 1200×1200 and I set max_srcset_image_width to 1200 and jpeg_quality to 60. It works great unless the user uploads an image with resolution between 600×600 and 1200×1200. Then WP will only make the 600×600 copy, and use the original image for any situation that needs larger image. Often these original images have very low compression ratios which results in double or even triple size of what they would have been if the image was processed by WP.

What I plan to do is make it so that when WP finds that a registered image size is larger then the original, then it will proceed by making a copy with the same size as the original. That way it will utilize the compression ratio that is set in jpeg_quality.

Any help appreciated.

civicrm – Hook name in module doesn’t seem to work

I’ve been at this for days, but I finally think I maybe kinda sorta found part of the problem, maybe…but I don’t know how to fix it.

I’m working on a Drupal site with the CiviCRM module running. I have a form on which I’d like to alter the data before saving it to the database. As a result, I’ve been struggling with getting ANY of the available CiviCRM hooks to fire.

I installed the civicrm_developer module, which is sort of a complement to Devel, in that it is used to help see into objects and other variables. Looking in the module’s .module file, you see all of the CiviCRM hook functions, which are being used in the module to dpm() whatever variables were passed to them.

function civicrm_developer_civicrm_buildForm($formName, &$form){
  drupal_set_message("hook_civicrm_buildForm called: formName is $formName");
  dpm($form);
  dpm($formName);
}

There are no includes or anything else, just hooks and printing variables, for each and every hook available in CiviCRM. The civicrm_developer module indeed works as intended. On the specific page I’m working with, there is a CiviCRM form and this module prints a populated Krumo above that form, as would be expected when dpm()-ing a variable in Drupal.

However, attempts at making a custom module which uses one or two of those same hooks, can never seem to get to that same data. I’ve gone far as copying the code from that module (just one .module and .info file) to my custom module and changed the hook nomenclature from “civicrm_developer” to, let’s say, “mymodule”.

So, my module, which is practically an exact copy of that module, with the exception of the hook name, will not generate a Krumo above the form as the civicrm_developer module did when it was enabled. Yes, I’ve made sure that my module was enabled.

For example, this is the same function from earlier as written in my custom module.

function mymodule_buildForm($formName, &$form){
  drupal_set_message("mymodule_buildForm called: formName is $formName");
  dpm($form);
  dpm($formName);
}

It might also be worth mentioning that the mymodule name in use is unique to that module. It doesn’t match the theme name or anything else that would cause a name collision, at least that I know of.

I can’t figure out why the same hooks work in a module but not the other. It just doesn’t make any sense.

reference request – Alternating sum of hook lengths

Let $lambda=(lambda_1geqlambda_2geqcdotsgeqlambda_k>0)$ be an integer partition and $lambda’$ be its conjugate partition. Denote the hook length of a cell $(i,j)$ in the Young diagram of $lambda$ by $h_{ij}(lambda)$.

QUESTION. Is there a formula for the following sequence? Or, a generating function?
$$f_n=sum_{lambdavdash n}sum_{(i,j)inlambda}(-1)^{i+j}h_{ij}(lambda).$$

php – Use wp_head hook on template page

I try to use the hook wp_head on a template page but this does not work

add_action('wp_head', 'to_head');

function to_head(){
    //do stuff
}

I place this code on a template part what is called by get_template_part( 'temp-parts/content/pages/catalog' );

Can you use the hook only on the functions.php or is there a way to use this on any page

functions – Overwrite text in a complicated filter hook

I am very new to PHP and WordPress. I have learned only the basics of filter hooks but this one seems to be a bit complicated. I want to replace the text This action will let you pay a deposit of and for this product preserving the value that is passed to %s. I am hoping that someone will be able to help me out. Thank you.

<?php
    echo wp_kses_post( apply_filters( 'yith_wcdp_deposit_only_message', sprintf( __( 'This action will let you pay a deposit of <span class="deposit-price">%s</span> for this product', 'yith-woocommerce-deposits-and-down-payments' ), wc_price( $deposit_value ) ), $deposit_value ) );
?>