Wordpress disable out-of-the-box rest-api, use library instead - json

In newer Wordpress, there is REST-API in the core.
Previously used plugin (specifically WP-API-1.2.3) had different API base URL (e.g. /wp-json/posts), but the newer one is using different structure (e.g. /wp-json/wp/v2/posts).
In order to be backward compatible, I want to support older version and not changing the base of API - otherwise, all other pages using this service would no longer work.
I found how to change the "wp-json" part, but not namespace "/wp/v2/".
Is there a way around how to use the original base path and in the best case to be sure nothing will go wrong to use the older library instead of the newer core functionality?
Disabling it in functions.php can't solve this issue - it's shutting down the lib.
add_filter('json_enabled', '__return_false');
add_filter('json_jsonp_enabled', '__return_false');
Thanks

Basically, there were 2 things I did and it's working:
rest_url_prefix was the same like in previous version (wp-json), paths were writing over each other (after requesting something like wp-json/posts went through the new core part of WP, not the lib).
function rest_get_url_prefix() {
return apply_filters( 'rest_url_prefix', 'newPrefix' );
}
I didn't click on Settings -> Permalinks -> Save changes
By doing this I am now able to use the original endpoints

Related

Create Vanila HTML / JS project inside PhpStorm where PHP has already been configured

I use Storm daily for PHP/Laravel, and hence have PHP configured. When I want to create a vanilla HTML / JS side project, Storm takes it upon itself to add the PHP libraries without asking. I don't want any PHP Libraries. When initially creating the project, I used "empty project".
Here is a screen shot to illustrate.
So, how to create an empty project without PHP libraries?
You are using PhpStorm, an IDE that supports PHP. That entry that you see there is a list of stubs for PHP (the stuff that IDE knows about core PHP and other common extensions: classes/functions/constants etc).
AFAIK it always will be there (as it's a PHP oriented IDE) and you cannot remove it. But you try this:
Settings (Preferences on macOS)
Languages & Frameworks | PHP
PHP Runtime tab
Uncheck ALL entries there.
If the above will not get rid of the whole node then you will have to ignore that entry. And I do not see any problems in having it here: it will not affect your JS/HTML in any way.
P.S. Whatever will be in a default/new project can be configured at File | New Projects Settings | Settings for New Projects...

Telling PhpStorm where a class is located so it can use autocomplete

I'm using WordPress and using a plugin called Timber, which basically helps you to utilise the Twig templating engine in WordPress.
Anyway, I am trying to do this in one of my files:
Timber::render('welcome.twig');
PhpStorm is reporting that Timber is an unrecognized class, because it doesn't see where I have included it; I assume it is being auto-loaded somewhere?
Now, I did a search around and came across answers about using PHPDoc such as this, however I'm not sure how to apply that to my situation, I tried:
/** #var \Timber\Timber */
...but it didn't seem to work.
If I can somehow do this globally that would be great, so I don't have to do it in every file I need to use Timber in.

'refactor' move files in VSCode - es6

If I move ComponentFoo.js from folder X to folder Y, than a bunch of import statements break. Looking into this it seems there are many solutions for typescript, but what about js / es6? If I move a file in the editor, it should find all the import statements and update them to the new location. Is this possible?
Old post, but this might help some Googlers. This feature can be enabled and disabled in User Settings. For Javascript and Typescript, it's called "Updated Imports On File Move".
I had apparently disabled it and just figured the feature was broken :X
VS Code has built-in support for this for both javascript and typescript since VS Code 1.24.
For JavaScript specifically, you need to make sure VS code's language support can find all the references to the file so that imports referring symbols in that can be updated properly. Definitely create a jsconfig.json for your project, and also consider enabling semantic checking for JavaScript so that VS Code shows when imports are not being properly resolved
If your project is configured properly but files are not being updated, make sure you are running the latest VS Code insiders build and report an issue if it still doesn't work
for flutter developers you should move files one by one. vscode doesn't support multi file moving with refactor yet.
Just use IntelliJ. It handles all kinds of refactoring perfectly. I'm a huge fan of VS Code, but refacotoring is definetly not one of it's stengths. Some imports don't get detected, and the imports can get modified in a weird way. For example, I had an import like this:
import { myStore} from 'src/common/stores/myStore';
When moving the file of myStore.ts to a different folder, VS Code constructed this bull**it:
import { myStore} from 'src/common/composables/myStoreStore';
The line above is no typo!
Btw I'm using vetur, maybe thats causing it, I don't know ...

Xcode Couldn't Generate Swift Representation for my own framework

I have created a framework which I want to use in my OS X app. Since updating to Xcode 7 on El Capitan, when I try to command-click on the import statement, Xcode goes to the following view.
How can I get Xcode to display the Swift representation properly?
I've had it happen before, and my solution was to recreate every project file which I don't want to do again.
From my experience there are two possible causes for this issue.
The first one is that your framework can't be located. To fix this you need to go to target's Build Settings and add a path to Framework Search Paths either an absolute:
/Users/{user}/path-to-framework-parent-directory
or relative to project directory:
$(PROJECT_DIR)/path-to-framework-parent-directory
Another possible cause is that the path to your framework contains a space in it. I found that it doesn't matter whether you try to escape it with backslash ../Project\ Name/frameworks or take the whole path in double-quotes "../Project Name/frameworks". The result would be that SourceKit could not load the module.
Note that $(PROJECT_DIR) could expand to a path with a space in it and it would too result in the same error. So it looks like a bug in Xcode/SourceKit (I tried the latest Xcode 7.2-beta3 and the bug is still there).
My repository was on the second hard drive /Voluems/Macintosh HD/Repos. I just renamed the hard drive to HD, so the path looks like /Volumes/HD/Repos and the problem was gone.
Max S. answer pointed me in the right direction, however I was using the 'recursive' option for my framework path.
To get things to work I had to explicitly add a path to directly the framework in question's immediate parent directoy (as oposed to just having a path to one of its higher up directories with the 'recursive' option set).
HTH
I had this problem too and the other solutions didn't work. I finally figured it out in my case:
The target name cannot have a space in it either
To rename it:
Go to your project settings
Expand the target list column on the left if not already there
Click on the relevant target once (or press Enter or Tab when having it selected) and type in the new name without the space
Weirdly, just changing the name of my folder from 'Developer' to 'Development' fixed the issue from me.
Running Product->Clean, Product->Build is what worked for me.
In my case, I have created a framework for my SDK along with podspec for making it cocoa pod.
I had the same problem when i use my SDK and it fixed when I imported Foundation API to the file where I am consuming my SDK
import Foundation
Here is another potential solution - one that worked for me:
After importing the framework I never built for simulator, only for real devices. Swift Modules were not showing up, same error. Then I built for Simulator and it suddenly worked, I could see the Swift Modules.
The reason is that when I make my framework, I have a step that copies the swift modules from the iphonesimulator build to the universal build, but does nothing with the modules from the iphoneos build. So my guess is that this is why it didn't work.
Note: once I selected simulator and built it started working all the time, regardless of the build destination.

phpstorm unresolved function or method $()

I have the following problem: phpstorm do not recognize jquery methods and here and there I see
Unresolved function or method $()
This was bugging me for sometime but finally I tried to get rid of it with File->Settings->JavaScript->Libraries and adding jquery as a global / project.
My library setup looks like this:
But is has not changed anything. I still see those pesky notices. Does anyone know how to get rid of them?
There is a really stupid workaround,
Download the Library (in this case jQuery) from inside the IDE itself.
Open up settings (Ctrl + Alt + S on Linux)
Navigate to Languages & Frameworks -> Javascript -> Libraries
Click Download and choose jQuery
Hopefully the errors will vanish
EDIT:
After running the IDE through Fiddler, I realised this only solves the problem because of the version the IDE downloads.
So, the correct workaround is to Add older, non-AMD jQuery versions as a Global scoped Library and add the latest one as a Project scope library.
The latest non-AMD versions are:
1.10.2 for 1.x series. And, 2.0.0 for 2.x series.
I had the same issue with version 1.11.2, and resolved it simply by adding the uncompressed version into my js folder.
Just copy the uncompressed version of jQuery into your project folder.
you don't even need to import it into your project, just copy it to javascript folder.
The jQuery v1.11.0 shows exactly the same behaviour here as well. At the same time previous version 1.10.2 works fine in IDE (no warnings).
I think it has something to do with "AMD-fy jQuery source" ticket (http://bugs.jquery.com/ticket/14113) -- looks like IDE has some issues figuring out this style.
If you wish (and can) -- roll back to jQuery v1.10.2 (which is like half a year old, which means it's stable and still good to use).
Hopefully IDE will be able to properly parse this new jQuery style in next release.
Actual ticket: http://youtrack.jetbrains.com/issue/WEB-10908
If you import both 1.11.0 and 1.10.2 in phpstorm it will be resolved
You don't have to rollback your project.