Array’s are technically preferred for both, but it actually doesn’t matter that much. PHP is not casting the object to an array, worpress is. wp_insert_post()
, like a lot of wordpress functions, runs it’s “array” parameter through wp_parse_args()
which will cast an object passed to it to an array and will always returns an array.
You should probably address it in case wordpress ever released an update where they stopped casting the object for you and PHP will throw a fatal error if you try to use an object as an array. But frankly, that casting probably isn’t super likely to be removed any time soon.
If you did want to fix it, all you would have to do is replace
wp_insert_post($object);
with
wp_insert_post(get_object_vars($object));
Related Posts:
- When to use Exceptions vs Error Objects vs just plain false/null
- Uninstalling a plugin: delete all options with specific prefix
- WordPress URL Rewrite not working
- Detect a focus on wp_editor
- simple wordpress ajax plugin not working when not logged in
- Utilize WP-CLI from inside WordPress, not SSH
- Saving metabox repeatable fields
- Why is PHP Cookie via plugin only set when logged in as Admin and not regular users? and other questions
- how to create and show sessions in word press?
- Disable External Pingacks on WordPress Posts and Only Allow ‘Self Pings’
- do not show web page section when using advanced custom fields pro
- How to get all existing post types
- Using wp_get_image_editor in a standalone script
- New Plugin Review
- Create custom blocks for bootstrap
- Continue execution after WP REST API response
- WordPress Ajax Custom Query – High CPU LOAD
- allow users to publish without admin approval
- action hook wp_head higher priority as all other plugins/hooks
- Query String being Removed Creating a Pagination Issue within a Custom Plugin
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Do my defines need to be unique?
- What does $wpdb->get_row return?
- woocommerce subscriptions – get expiration date [closed]
- WordPress Scheduled Event Request Blocking
- Delete a WordPress transient from a shortcode on Page/Post update
- Plugin CSS not enqueing
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Saving an array of dynamic repeater data as post_meta
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- Improve page speed loading using CDN and async or defer attribute
- How to call plugin function per site in a multisite?
- Script to browser problem PHP
- Store a default value for a transient on plugin activation
- Options API get_option() and update_option() Not Correctly Updating or Returning
- wp_head function not outputting
- wp query foreach deleting record returning only first or last item
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- How to make own crop image function for WordPress plugin
- WordPress Custom field Colors
- “Undefined index” error when saving empty array with checkboxes
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Building a REST API for your web app exposes primary keys of DB records?
- How to remove the message ‘We could not find any results for your search’ without changing template files and without adding posts/pages?
- Custom meta box values are not getting saved for my custom post type
- Can’t upload CSV file to plugin directory using custom upload form in admin panel
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Custom Registration username_exists / email_exists
- How can I search all plugins for composer’s vendor/autoload.php?
- Action Hook Inside WordPress Plugin Shortcode
- Can I remove or edit an include() from a function with a filter?
- Call to undefined function error in plugin
- Submit form to db
- Get category id when SEO URL is turned on
- Add a custom WooCommerce settings tab with sections
- PHP using external anonymous function inside class
- Using ACF Relationship field to set post type to draft or published status
- Add Pre-Defined Value to Click Counter in WordPress
- How can i avoid duplicate same post in wp?
- Drop down question
- How do I disable cache for a certain page?
- code that I can run, or a plug in to show what sql tables something pulls information from
- Automatic email message after manual user approval
- How to check if plugin update process completed in wordpress?
- custom mailchimp form using HTTP API
- How to override theme’s public static function inside of a trait?
- pass datetime using wp_localize_script to frontend from settings page
- add custom metabox to media library custom widget
- using filter and hook inside class
- Display attached images of a page or post that are insetred using gallery
- overwrite wordpress gallery with custom gallery shortcode
- Enqueue sripts and styles only if function is called
- Add widget area from visual editor
- Register/enqueue scripts only on certain admin pages
- Looping through custom data in a custom table to display all items in a post
- Priority call methods – PHPMailer->addAddress(NULL)
- How to properly escape in ternary operators – Wp Coding Standards?
- not able to access $_POST on backend profile update
- Custom Plugin Develoment, Form Action
- WordPress Query Crashes Browser
- How to send logs to plugin owner for a plugin?
- How to Request a User to Register on Landing at a Site, Then Automatically Delete the Users Password on Logout?
- Plugin Modification Change Functionality For Logged User Only
- Force CSV download with template_redirect
- How to use foreach and if statement within array of arrays?
- INCOMING: Wall of code for form and $_POST, not updating custom field’s value
- add shortcode heading showing multiple time
- WP multisite network plugin fails to see classes loaded with spl autoload
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- What is this mark for “? function()” [closed]
- Cookie not created in AJAX request
- using a shortcode in a hyperlink
- How to automatically convert images to WebP on WordPress?
- Check user last login date
- Login user into magento using wordpress account
- Redirect users by role to custom pages
- getJSON response to PHP
- Custom plugin with shortcode not working
- Customize create table SQL statement in any WordPress plugin
- wp_register_script – illegal string offset