Skip to main content
2 votes
Accepted

Is there a way to enforce the type of an object returned by a function that could return anything?

In addition to what Tom already said, using instanceof has worked quite well for me. (Actually never heard of is_a() before.) if (is_singular() && $queried_object instanceof \WP_Post) { //...
kero's user avatar
  • 6,200
2 votes

Is there a way to enforce the type of an object returned by a function that could return anything?

No, you can't change what a function returns without modifying it. You can, however, do several other things: Provide type hints on your constructor's arguments, your IDE and PHP will then know that ...
Tom J Nowell's user avatar
  • 59.3k
1 vote
Accepted

If you already have a copy of the code, is there any reason to create a feature branch?

Yes, if you are asked to create a feature branch, do that. If you already have code in your IDE, you may have the main branch. Creating a branch, you'll create a copy of the code separate from the ...
dooley's user avatar
  • 36
1 vote

Unable to get a simple plugin admin page to work

Well, as it usually goes, after banging my head on this for hours yesterday and then finally deciding to ask for help, I was able to solve it within a few minutes. Here is what I needed to change: ...
helgew's user avatar
  • 111
1 vote

PHPUnit Plugin Integration Tests: Getting wordpress-tests-lib PHP into IDE (VS Code)

The best solution I've found is to make a symlink from the plugin directory to the actual location of the /wordpress-tests-lib/. At least in the case of VS Code, the symlink seems to help it "...
jerclarke's user avatar
  • 3,043
1 vote

How can I Edit WordPress Page in IDE like PhpStorm or Sublime?

First of all you need to understand how wordpress works. In your local wordpress instalation directory you can find only files that are responsible for markup and functionality. Those files contains ...
Bartosz Was's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible