Where is "views" directory in WordPress installation? - wordpress

This might be a stupid question but I am not able to locate the "views" directory inside my WordPress install!
I need to do some work in media-views.js, which is located in wp/includes/js directory. At line 2291, it has the entry:
media.view.AttachmentFilters = require( './views/attachment-filters.js');
I tried
sudo find ~/ -type f -name 'attachment-filters.js'
sudo find / -type f -name 'attachment-filters.js'
(staying at WordPress installation root) but did not find the file.
When I tried to search views directory with
sudo find . -type d -name "views"`
it only fetched
./wp-content/plugins/akismet/views!
Please help!

General answer
As I understood, the wp-includes/js/media is only in the source code (in github). Those are js modules that are then concatenated and transformed by their build pipeline.
See this issue: https://core.trac.wordpress.org/ticket/28510
Split javascript files in media into modules: This will only affect the src/ directory in the develop repository, which will use our build process to concatenate into the build/ directory, so nothing will change for developers using the build/ directory or the core repo.
We'll start this effort with media, and end up with a standardized way of doing this going forward.
To better understand how all of this works, I suggest this article https://make.wordpress.org/core/2015/01/22/the-case-for-js-modules/, which explains the WordPress Backbone more in depth.
As for your specifiy need
In WordPress, you use themes, plugins, hooks and filters to customize your site. You don't alter the source code directly !
If your need is to define custom attachment filters, you need to use filters, they are there precisely for that. Have a look at https://code.tutsplus.com/articles/quick-tip-add-extra-media-type-filters-to-the-wordpress-media-manager--wp-25998 for an example.

Related

Wordpress plugin path configuration

I am working on a local environment and I am pulling down a plugin that has its own git repository that is linked to the production server (also staging server). The only problem is that the plugin folder itself is in a folder like so:
repository-folder
real-plugin-folder
And my plugins directory looks like so:
plugins
plugin1
plugin2
plugin3
repository-folder
real-plugin-folder
plugin4
Is there a way to define a new path for this one particular plugin so that it will show up in my local environment and so I can edit it while keeping the plugin git repository structure in contact so I can push up to that repository? (some sort of path definition in wp-config.php?).
I think Git submodules might be the answer? But honestly I don't have time to tinker with it: https://git-scm.com/book/en/v2/Git-Tools-Submodules.
Why don't you just start your repo in "repository-folder" ? You don't need to follow the same parent folder in git.
I hope it helps you at least a clarification here
If you are on a Linux environment, setup a symlink for the plugin:
cd plugins
mkdir real-plugin-folder
ln -s respository-folder/real-plugin-folder/plugin.php real-plugin-folder/plugin.php

Testing plugins live with Varying Vagrant Vagrants

I'm currently trying to use VVV to develop and test my plugins. My host OS is Win10.
My plugins are in D:\Workshop\projects\vendor\module. I've used this folder structure for a long time, and it is really convenient, especially for use with Composer and friends.
Now I've installed VVV, created a site with VV. I want to test a plugin, the source code of which is in D:\Workshop\projects\XedinUnknown\my-project. So, I create a symlink in D:\Workshop\projects\XedinUnknown\vvv-local\www\my-test-site\htdocs\wp-content\plugins that points to that project's folder. Alas, it doesn't work. If I SSH into VVV and ls /srv/www/my-test-site/htdocs/wp-content/plugins, I can see my-project there, but it points to ../../../../../../../XedinUnknown/my-project, which, of course, doesn't exist. If instead of symlink I create a junction, it's just an empty file.
I suspect that this has to do with how the Linux environment handles Windows symlinks, but I'm not entirely sure. Is it possible to make this work somehow? I really don't wanna copy the whole project folder into VVV.
This is also addressed here.
So, it would seem like I've found somewhat of a solution. I added a synched folder, which maps to my projects home. I then create a symlink to that folder from the WP plugins directory, inside the VM.
Step 1 - Add Shared Folder
This should be done in a Customfile as explained here. This file should go into the same directory as the Vagrantfile, e.g. it will become the Vagrantfile's sibling. In my case, if you're following along from my question, it is in D:\Workshop\projects\XedinUnknown\vvv-local. Anything put here becomes global for the whole of VVV. This also gives you the ability to use different combinations of your projects in different websites. Add these contents to your Customfile, creating it if it does not exist.
config.vm.synced_folder "D:/Workshop/projects", "/srv/projects", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
Of course, you should replace D:/Workshop/projects with the path to where you store your projects. Note the forward slashes (/). This works on Win/Nix. For a Windows-only configuration, I suspect you'd have to replace them with \\, because this is an escape sequence.
Step 2 - Add Link to Project
This should be done in your site's vvv-init.sh file. In my case, this file was in D:\Workshop\projects\XedinUnknown\vvv-local\www\my-test-site\, because I want to create this symlink specifically for the my-test-site site. Please note that your VVV path will probably be different, and it doesn't have to be inside the projects directory. It's wherever you cloned VVV into. Add the below lines to your site's vvv-init.sh file.
if [ ! -f "htdocs/wp-content/plugins/my-project" ]; then
echo 'Creating symlink to plugin project...'
cd ./htdocs/wp-content/plugins
ln -s /srv/projects/XedinUnknown/my-project my-project
cd -
fi
In the above snippet, change the path to your desired project path, keeping in mind that /srv/projects/ now maps live to the projects root in your host OS. You can also replace the second occurrence (last word) of my-project in ln -s /srv/projects/XedinUnknown/my-project my-project with whatever you want. As long as you don't change it later, your plugin should not suddenly get de-activated.
Also, from what I understood, vvv-init.sh runs during provisioning, not every time the machine is brought up. So, if you want to run the code in there, you have to run vagrant up --provision from the VVV directory. If you don't want to provision, you can run it manually. SSH into VVV with vagrant ssh, then cd /srv/www/my-test-site (replace my-test-site with name of your site), and run . vvv-init.sh.
Afterword
I am quite new to Bash scripting, and I don't know if my solution is the best one, so please feel free to suggest better versions of the Bash script. I also don't know Ruby, and am new to Vagrant, so please feel free to suggest improvements to the Customfile - this is in essence the same as the Vagrantfile.
One possible issue that I can anticipate with this solution (and this is inherently by design of the filesystem architecture) is that if WordPress decides to make changes to your plugin, e.g. if you run a WP update, it will effectively delete all files in your project, including the repository. So, on the testing site I would recommend using something like this. I am in no way associated with this plugin.

How to install site-specific modules in a Drupal 7 multi-site?

I have a "multi-site" installation of Drupal 7, which means that I have these folders in my "sites" folder:
all
domain.one
domain.two
domain.x
And in each of these folders, I also have "modules" and "themes" folders.
If I click the "install new module" link on the modules page ("admin/modules") from any domain X, Drupal tries to download modules in the "all/modules" folder instead of the "X/modules" folder.
Maybe I am not using the proper phrase to search in Google, but I do not see similar problems, so it may just be my problem.
How to install site-specific modules in a Drupal 7 multi-site?
You can try the example detailed out in this post: http://www.pixelclever.com/how-set-up-drush-for-multisite-installation which basically requires you to create a drushrc.php file for each multisite, which includes the path to the respective modules folder.
Here are the lines from that post that explain
To start, go to your drush folder where you will find a file entitled example.drushrc.php. Copy that file into the individual site folder in your Drupal multisite installation (sites/yourmultisite), and rename the file to drushrc.php.
Now open that file and add the following line:
$command_specific['dl']['destination'] = 'sites/yourmultisite/modules';
or
$command_specific['dl']['destination'] = 'sites/yourmultisite/modules/contributions';
This is also a step by step walkthrough of the updating process using drush on multisites.
http://rinen.net/2013/02/updating-a-drupal-multisite-using-drush/
I found good article for multisite install here,
http://mydons.com/drupal-7-multisite-install-steps-in-linux/
http://mydons.com/drupal-7-multisite-install-steps-in-windows/
This worked for me:
Changed working directory on terminal to specific site directory
i.e. "cd [drupal_site_directory]/sites/[site_one]/ "
use usual drush command to install modules i.e. "drush dl [module_name]"
Hope this might help you guys also.
.

What are all of Wordpress' public/direct entry-points?

I realize this is a bit of a strange question, but to put a long story short, we have a few Wordpress installs whose files are loaded through a symbolic link (the symlink is in the document root whereas Wordpress is not).
For this to work, I need to have a list of all Wordpress files that are usually loaded directly from the web browser (either by the user or through AJAX), such as: index.php, wp-login.php, (all theme files)* ...
An example of files that are not loaded directly: wp-load.php, wp-config.php, wp-blog-header.php...
[*] Theme files are an exception; they actually exist in the document root.
Edit: You might wonder, what is the point of this? It is so that we can cut down on the extra files on the server; it's useless to have thousands of identical files from each Wordpress website. The wp-content directory has been left there since it's what changes between websites. Am I aware of the consequences of such a set up? I believe I am.
Edit 2:
http://codex.wordpress.org/WordPress_Files
Here is a list of entry points based on require( 'wp-load.php' );
https://github.com/szepeviktor/WPHW/blob/master/wp-entry-points.md
And a Trac ticket about their deficiencies
https://core.trac.wordpress.org/ticket/28364
So far, the following fixes my issue:
ln -s /var/www/vhosts/mainsite/httpdocs/index.php /var/www/vhosts/subsite/httpdocs/index.php
ln -s /var/www/vhosts/mainsite/httpdocs/wp-login.php /var/www/vhosts/subsite/httpdocs/wp-login.php
ln -s /var/www/vhosts/mainsite/httpdocs/wp-admin /var/www/vhosts/subsite/httpdocs/wp-admin
ln -s /var/www/vhosts/mainsite/httpdocs/wp-includes /var/www/vhosts/subsite/httpdocs/wp-includes

How do I find where ElasticSearch is installing my plugins?

I have installed elasticsearch with brew install elasticsearch. My plugins seem to reside in /usr/local/Cellar/elasticsearch/0.19.8/plugins. With cat $( which plugin ) I see a ES_HOME variable that contains the correct path.
Is there a way to ask elastic for ES_HOME or the plugins directory?
EDIT
What I am looking for is the directory used by the plugin executable to install the plugins when I do plugin -install something. I want to use that path in a script to fire up elastic search.
To find your elasticsearch home directory & install plugin(s) follow these steps below.
Locate your home directory ( Look for Settings -> Path -> Home for value )
$ curl "localhost:9200/_nodes/settings?pretty=true"
Goto Location (Example settings.path.home value: /usr/local/Cellar/elasticsearch/1.5.0)
$ cd /usr/local/Cellar/elasticsearch/1.5.0
Install Plugin (Example plugin: mobz/elasticsearch-head)
$ bin/plugin -install mobz/elasticsearch-head
I used this command:
$ curl "localhost:9200/_nodes?pretty=true&settings=true"
Check next setting: nodes - settings - path - plugins and use it as your plugins directory.
I had the same problem as you and I was able to locate the ES_HOME directory by following
#imotiv's suggestion.
Simply call PATH_TO_SERVER:9200/_cluster/nodes?settings=true&pretty=true
Therein you'll see the path.home entry. That is your ES working directory.
Once you locate your ElasticSearch home folder, in my case /usr/share/elasticsearch, cd down to that location.
Once there, you could simply run bin/plugin -install elasticsearch/elasticsearch-analysis-phonetic/1.3.0 and it will automatically do the rest for you.
Hope this helps.
Not totally sure what you are trying to achieve, but hopefully this will help. There are a couple of way to find the plugins directory for elasticsearch. You can set plugins: TRACE in the logging.yml file, it will cause elasticsearch to log the full path of plugins that it's loading. You can also execute
$ curl "localhost:9200/_cluster/nodes?settings=true&pretty=true"
to check the current settings. Elasticsearch is using location specified in the path.plugins settings to load plugins. If path.plugins is not set, it will use plugins directory in the directory specified by the path.home setting.

Resources