PHPStorm and WordPress project errors - wordpress

I'm using PHPStorm while develop WordPress plugins (mainly for HTML/CSS/JS).
Each plugin is a separate PHPStorm project since I can have several goodies from using this way.
The issue is when working on a plugin, the WordPress functions like _e are marked as Warnings (yellow color) and the information PHPStorm gives is that
"Undefined function _e"
How can I configure PHPStorm that it understand the WordPress functions and do not shows that errors and autocomplete the functions without to have a big project wrapping the WordPress installation?

You need to reference WordPress code in some way. Few possible approaches:
Add as External Library -- perfect for referencing only: Settings | PHP | Include paths
Add as part of the project itself (careful, as in this case WP code will be used during Search/Refactor/etc operations) -- Settings | Directories | Add Content Root
Symbolic link somewhere in the project (but #2 is still better for your case)

Related

How to add wordpress plugins in docker-entrypoint.sh file

I had researched about adding WordPress plugin in WordPress docker image, as in research I found the custom plugins can be added in docker-entrypoint.sh file. But I am not able to add custom plugins in entrypoint file. If is there any solution for this problem.
The docker-library/wordpress image does include a wordpress/docker-entrypoint.sh script.
However, the README points out:
This image does not provide any additional PHP extensions or other libraries, even if they are required by popular plugins.
There are an infinite number of possible plugins, and they potentially require any extension PHP supports. Including every PHP extension that exists would dramatically increase the image size.
So when you say "I am not able to add custom plugins in entrypoint file", it really depends on what error you have.
If you need additional PHP extensions, you'll need to create your own image FROM this one. The documentation of the php image explains how to compile additional extensions.
Additionally, the wordpress Dockerfile has an example of doing this.

Static html to wordpress migration

I have a static HTML site (about ten years old) which I am going to migrate to a Wordpress site.
I have used Wordpress before but never as a migration target. From some initial background reading I have come up with the following process to perform the migration:
Check hosting provider/package for Wordpress suitability
Generate complete current site map
Make a complete backup of current site
Install Wordpress in subdirectory
Install Maintenance mode plugin and activate
Migrate content to Wordpress instance (looks like this could be
painstaking..)
Install suitable theme
Customise selected theme with Logo/fonts/colours etc.
Deactivate maintenance mode
Make Wordpress site available from domain root
Delete old static html site files
(The migration may take place over several weeks/months so I need the static HTML site to be available until step 10 is completed)
In my naivety are there any pitfalls in the above process, or additional issues I have failed to consider?
Are there any other accepted 'best practices' when performing this kind of migration?
Here's a good tutorial:
http://code.tutsplus.com/tutorials/creating-a-wordpress-theme-from-static-html-creating-template-files--wp-33939
For developers who want the theme converted from HTML in easy way (but no guarantee if it can produce the output as expected):
http://www.htmltowordpressconverter.com/
Hope this was helpful!!!!
WordPress theme styles come in all shapes and sizes. Converting from a static HTML site to something database driven like WordPress can be as easy or complicated as you want.
If you just want to integrate WordPress into an existing HTML theme it's as easy as installing WP, setup the database and config, then building in the old HTML structure using WP. This way everything will be the same but managed within WordPress i.e. Pages, Menus, Sidebars.
Here's are some useful links:
https://codex.wordpress.org/Using_Themes
https://codex.wordpress.org/Theme_Development
https://codex.wordpress.org/Stepping_Into_Templates
And here's a "Start from Scratch" theme that would be simple to start from. Just install it, activate it, then begin migrating the main content i.e. copy and images etc, and building the theme itself.
http://adopttheweb.com/start-from-scratch.zip

Wordpress Plugin & Paths

Hey guys I have a plugin and its displaying info on /courses.php (using theme)
How can I get it to display info on /courses/single_course.php
I figured I'd just have to make a /courses/ folder in theme and have single_course.php inside that. However this doesn't seem to work.
I've tried googling but I'm struggling to figure out the keywords to solve this problem! ^_^
OK edit cause nobody is understanding:
I have plugin working. This is a custom plugin
I want to know how to make the following work http://www.example.com/plugin/index.php http://www.example.com/plugin/index.php
Currently to make http://www.example.com/plugin work you just need to create plugin.php in the theme directory and give a callback to a function in the plugin.
Creating /wp-content/theme/themename/plugin/index.php did not work as anticipated.
WP uses specific directories for placing its themes and plugins tom maintain organization standards.
// Pointing to theme WP themes directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/themes/"
// Pointing to theme WP plugins directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/"
or you can use the built in functions in wordpress
// for themes in any php file after headers
get_template_directory_uri() . '/js/custom_script.js'
// for plugins in you main plugin class
plugins_url('/js/newscript.js', __FILE__);
I would recommend keeping plugins in plugins and themes in themes. What you may be looking for is creating some extra plugin features which will require you to include you extra php functions and classes when the plugin in question is loaded.
First create a folder in under your plugin directory and chmod it with proper web securities
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
mkdir php
chmod 755
Next either copy or create and edit the new single_courses.php file. I've listed a quick method below if you are creating the new file from scratch. Otherwise just cp it over. In both cases we need to insure proper web access right using chmod.
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
echo -n "/*Extra Plugin Functions*/" > single_courses.php
chmod 644 single_courses.php
Now we need to be sure to include the new file in our main plugin file
/* Main Plugin File :: ./wp-content/plugins/your-plugin/theplugin.php */
...
include_once $_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/you-plugin/php/single_courses.php"
...
Thats the basic way to go about it. Use the same process for hooking theme php files as well. Always make sure when creating directories and files on your server that proper security is put into effect or you open up your web directory and or server to get hacked.
Hope it helps...
You have to give us more information on what plugin you are using and what you are trying to achieve. The solution may be as simple as pasting a Plugin provided shortcode into the post area of the desired page. Alternatively you may have to edit the plugin itself.

Using Wordpress in CakePHP for views

I'm using the latest version of Wordpress for the public portion of my site and CakePHP for the actual web application. Since I want to keep the application consistent, I want to use Wordpress functions (for example get_header(), get_sidebar(), and get_footer()) to achieve this in my view files. Can I just use an require statement and call in the functions I need? Has anyone done this? Would there be any conflicts (e.g. functions with the same name) and is there a way to avoid it?
Additionally, I know CakePHP usually assumes path are relative to the app/ directory. Is there a way to get around this?
I recently tried something similar. You would be combining both codebases, and yes, there are name collisions. PHP5 namespaces would fix this, but they are only planned for CakePHP 3.0.
I'm not sure about including certain parts of WordPress into a CakePHP app, it would probably get quite messy and WP might fail if its being loaded in a different path to what it expects. Unless someone else has done it before you might find yourself doing a lot of work and discovering that it can't be done at all.
There are some guides to installing them side-by-side, but nothing seems to cover grabbing posts, and parts of the template from WP in Cake.
Here are the some options I would think about:
1) Having WP located in /blog and simply make sure your WP theme matches your CakePHP layout visually.
2) Build a simple blogging platform into your Cake application.
3) Build the CakePHP part of your application as a WordPress plugin.

Have wordpress as a module or extension in Yii

I would like to add a blog to a web site. Couldn't find any good blog extension for Yii, so I decided to just use Wordpress. (Please let me know if there's a better way)
I could just extract wordpress in the root folder and run it.
http://www.example.com/wordpress
However, the Yii framework has its index.php on root folder so I will have to make wordpress either a module or extension (I think) unless I put the Yii framework in a root/yiiFolder and use root/wordpress to separate the two. Also, the main layout will have to be different than the Yii default main layout. Otherwise, the blog will share the same header and footer structure of Yii.
Could someone give me an example on how Yii framework call a non-yiiframework site?
If you are having the following error:
include(Translation_Entry.php): failed to open stream: No such file or directory
then you need to disable Autoload, for example like this:
spl_autoload_unregister(array('YiiBase','autoload'));
$wp=dirname(__FILE__).'/../../../../wp-load.php';
require_once($wp);
spl_autoload_register(array('YiiBase','autoload'));
http://wpengineer.com/1038/embed-wordpress-functions-outside-wordpress/ - here is described how to call wordpress functions from outside wordpress. I tried the same thing from Yii layout and now I'm facing strange error. include(Translation_Entry.php): failed to open stream: No such file or directory. I need to look a little more into this.
Other than that - this solution (if you manage to configure it) should give you what you want.
You can include wordpress as a library, and require_once 'wp_config.php' in index.php. Then you can call wordpress function directly.

Resources