0

I am developing a custom importer for WordPress (because we have a very custom setup and the available tools don't seem to work for our scenario).

During this import, I'd like to disable any hooks there is when creating/updating a post. For instance this hook is being fired, and it is generating some errors:

            add_action(
                'woocommerce_process_product_meta_simple',
                array( $this, 'on_simple_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

            add_action(
                'woocommerce_process_product_meta_variable',
                array( $this, 'on_variable_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

            add_action(
                'woocommerce_process_product_meta_booking',
                array( $this, 'on_simple_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

            add_action(
                'woocommerce_process_product_meta_external',
                array( $this, 'on_simple_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

            add_action(
                'woocommerce_process_product_meta_subscription',
                array( $this, 'on_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

            add_action(
                'woocommerce_process_product_meta_variable-subscription',
                array( $this, 'on_product_publish' ),
                10,  // Action priority
                1    // Args passed to on_product_publish (should be 'id')
            );

Is there a way to disable all actions? Or should we run a custom MySQL query to insert into database instead?

  • wp_insert_post() is very very slow, even slower with woocommerce. But, if you want to write your own function then you'll have to re-create a lot of functionality which is buried within wp_insert_post() and cannot be separated from it. So, you lose either way. The hardest thing(s) about writing your own update function would be ensuring the correct date format on all columns, generating the guid column according to the sites chosen permalink structure, and ensuring uniqueness among post names. Again, all of this logic is mostly inseparable from wp_insert_post(). Good luck. – Joel M Oct 3 at 0:36
  • 1
    Are you importing WooCommerce products? You might find that some of these hooks are necessary to products to be set up properly. – Jacob Peattie Oct 3 at 0:56
  • Jacob is probably correct. If for example, woocommerce tries to sort products by price in some page, it will do a meta query. Meta queries that sort by some entry require the entry to exist in the database. In this case, a product without a price is not the same as a product with an empty price. I don't know that woocommerce does this, but its just one example of what might happen on those hooks. – Joel M Oct 3 at 1:30
  • On another question, I demonstrated a partial way to insert a post without using wp_insert_post. However, the purpose was to insert posts fast, and had nothing to do with avoiding hooks, like in your question. I actually highly recommend that you don't use what I wrote there, but you can take a look at it to get an idea of what it would take. wordpress.stackexchange.com/a/349642/93297 – Joel M Oct 3 at 1:42
  • Ok thanks for all your answers. is there a way to disable specific hooks then? Like the facebook hook. – FooBar Oct 3 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.