Creating a plugin that adds functionality to a theme - wordpress

Divi is a wordpress theme https://www.elegantthemes.com/gallery/divi/. It contains a video module https://www.elegantthemes.com/gallery/divi/documentation/video/ that allows you to add the URL of your video and then view it on your website. Currently it supports Youtube, Vimeo, etc. however does not support Wistia. Without going into detail Wistia is the only option I can use, and therefore my aim is to create a plugin that adds this functionality. However I'm going into the unknown and want further direction. My first objective would be to look into the theme code and find out how the theme is adding this functionality for Youtube, Vimeo, etc. Exactly how would I find the code? And then why wouldn't this functionality have been added to begin with? Would they have just left it out, or would it be another reason that might be preventing me from adding the functionality?

Every single include/embed/attachment etc. that loads from an external source, into Your app is done trough the usage of an API which Your source provides.
You won't be able to find much in their code since this is probably being done trough some custom shortcodes or hooks. In both situations, this requires custom modifications from their developers in order for the Westia API to work with the DIVI builder.
In Your particular case, Westia do provide an API but if DIVI didn't include that yet, I presume that this is because of the fact that Westia is a Niche video hosting provider, not a public one like Youtube / Vimeo. Therefore, I think that You should contact their support for more information on that issue.
You can try to embed your desired wisita video trough a custom object of some kind.
So in this case, You can go trough this thread right here by Elegant themes, and after you get acquainted with the methods to do so, head over to WISTIA's embedding options page and find out what fits your site best.

Related

Advanced Custom Fields in wordpress

I am making my first steps learning to code. I made some courses on Internet and now I am building a Wordpress theme to continue learning from the experience.
The thing is that I am learning how to install a jquery slider plugin and I see that it's necessary to install advanced custom fields plugin and the repeater plugin that is only available in his pro version ($25) and that's not cool...
Now I would like to know if there is some free good plugin with the same functions of advanced custom fields?
I am just starting my experiments with wordpress to learn everything that I need to start building sites, so I don't have the enough experience to know if it worth to pay the $25 for the advanced custom fields plugin or not.
Do you have some suggestion? It will be something useful in the future? Are there other plugins that you recommends to download even if I have to pay for them?
There's so little context around what you're using the slider for and how much the site admins would need to update slides, etc., but I have two comments:
Do you need to use that specific slider? You could rig something up with custom post types, hide the editor and metaboxes, leave only a field for an image upload and whatever meta you like, and have the admin user just add a new post for each slide. Generate those posts in the PHP and have the jQuery slider take it from there. If you're just learning code, that might be more of a challenge, though. I just tend to resist paying for things when there are reasonable alternatives out there.
ACF is a worthwhile plugin. If the general context-free question is "Is ACF worth the $25?", the answer is 100% 'yes.' I use it virtually every day and often wonder how I'd make use without it. In your case, if you have other potential use for the project you're on, then yes, I'd say it's worth it. But still, in the simple context of a jQuery slider, I'm hesitant to purchase it just for that.

Custom code in Wordpress: what are the programming limitations?

I have a website (www.easterisland.travel) that I'm considering converting into a Wordpress site. Why? Basically for the following reasons:
1: To use a CMS, so that I can teach others to further add content to the website without having programming knowledge. I would built the advanced pages myself though, and the pages that others would manage would be simple information pages.
2: Access to all of these great plugins, for example the "similar pages" plugin at the bottom of each page (which I haven't found as a independent solution for raw webpages), which is just fantastic to keep people reading.
At my site I have lots of custom stuff like booking systems that I've created. There's an AngularJS shopping cart (www.easterisland.travel/tours/), instant online booking and payment (using PayPal's Express Checkout) etc. There's a page for cruise ship shore excursions (www.easterisland.travel/cruise-ship/) that's automatically generated from database data, and I've created a system where I can add cruise ships and shore excursions (adding correct itinerary, price, info etc). Passengers can also log in and communicate to other future fellow travelers within the same group, and get organized for meeting up on the tour day. I have many more plans to go as well, for example showing hotel info, displaying TripAdvisor data (using TripAdvisor API) etc.
The million dollar questions are:
1) Can all of this be achieved in a Wordpress site? Can I add all of these systems using this platform? What are the limitations?
2) Would it make sense to change to Wordpress?
3) What implementation should be used? I don't want my code to be removed or altered when Wordpress is automatically updated.
Thank you!
Wordpress doesn't have any limitations, you can extend its default functionality if it can't accomplish what you need with either plugins or custom code. and having a framework is always better than building from scratch in many ways.
HOWEVER, wordpress was originally design as blogging platform, and if you plan on extending its simple functionality you should take some time to understand how it works to properly integrate your custom needs or things could get ugly,
If you know how to interact with the database, you can easily do what you want, there are built-in functions you can use according to your needs for database interactions or just create your own if it doesn't fit well very much.
just a quick overview with wordpress database.
wp_posts - where sites main front-end data are stored, like posts, pages,
wp_postmeta - storage for additional data that are stored on wp_posts
wp_comments - storage for user interaction data for wp_posts like comments, I've also used these before to store user/admin messages.
wp_terms - use for dividing/categorizing wp_posts data, like categories and tags,
wp_options - use for back-end storage data and configuration.
You'd need to check out these functions as you're probably will encounter them in the future
https://codex.wordpress.org/Function_Reference/add_post_meta
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Function_Reference/update_post_meta
https://codex.wordpress.org/Function_Reference/register_post_type
https://codex.wordpress.org/Function_Reference/register_taxonomy
https://codex.wordpress.org/Class_Reference/WP_Query
If you also need database interaction, check out https://codex.wordpress.org/Class_Reference/wpdb
and for front-end implementation, check this out https://developer.wordpress.org/themes/basics/template-hierarchy/, though I never used any other wordpress theme except Genesis Framework for these past 5 years as I never had to mess too much with HTML codes and almost everything can be customize using actions & filters. I advise you to use Theme Framework (and remember to always use CHILD THEME to be safe from Main Theme upgrade)
You might also want to check -> https://github.com/WebDevStudios/CMB2 (I prefer to use this than Advance Custom Fields plugins.)
Booking system in wordpress is a bit complex, I've successfully use gravity form as booking system with AngularJS + Ajax, but never tried a custom one from scratch and don't have a chance to use booking plugin as never encountered a cleint that wants a simple booking system.
Just to answer your question.
Yes, It can, for comparison, take a look at woocommerce plugin functionality and features, I believe thats more complex than what you need.
It would make sense to convert a site built from scratch to any CMS (wordpress is an option), the CMS is up to you, though its better to use the one that you know more for easier integration and customization.
You can use your child theme "functions.php" for extending your custom functionality, like create a folder in your theme for all your custom code and include/require it on your child theme functions.php or better create your own plugin to properly integrate them, you can divide the functionality in plugins, like plugin for booking system and plugin for payment functionality. check this out https://github.com/hlashbrooke/WordPress-Plugin-Template
I hope this would give you an idea.
Yes you can do all that. You will need someone with knowledge in wordpress themes and plugins but it is possible. The beauty of wordpress is, that you can write "bare" php code, and the small amount of functions to interact with wordpress are well documented.
Wordpress itself, is structured "simple" (compared to fancy tools like magento for example). So all it manages, are posts / pages / ... which, more or less derive from the same database object. You can add functionality to those things (for example, make posts cruise ships and other posts to shore excursions) or you can add your own database structure on top.
The theme system is bare php code, so you dont have to crawl through a thousand lines of xml codes to adjust little things.
Wordpress power derives from its simplicity of the "core wordpress" and the feature volume based on all those plugins. I believe alot of people would say, that you should go for a custom solution (based on symfony for example), or a CMS that already comes with more of your desired functions (like magento which has the checkout / paypal included), but I (as a wordpress fan) would see no problem to take wordpress.
I have never failed to find a plug-in to do what I needed! I manage three WordPress sites - although none of them is commercial. (Yacht Club, Cycling Club and Political Party EDA).
There is a plug in that allows PHP on any WordPress page, but it means that the Editors all have to write using the text (HTML) view rather than Visual tab. I found that useful for some of my pages - and I'm the only "Editor."
There's also a plug-in that allows you to code PHP in Widget. That doesn't have the above disadvantage.

WordPress technical theme design

In a typical WordPress project I guess there are 3 parties. Party 1 is the graphic designer providing psd/pdf or html that party 2 (the developer) will create a theme from with probably some custom posts so party 3 (the client and content editor) can update the site without messing up the design and with no knowledge about HTML, JavaScript, Gimp or PHP.
This would tie the main theme of the site or it's specific pages in the php page(s) and if some minor design changes need to be made it needs to be done through editing php files.
I was thinking the following for a theme design:
(assuming a content only site without having complicated sales statistics and such)
Instead of "programming" the page.php to fit the graphic design and bring in specific (custom) posts and other data I would have the page.php bring in sub content. This so the graphic designer can create the page without having to program.
When images need to be provided then wordpress can pre scale/crop for different screen sizes.
The entire page should be created from the editor by the designer NOT the editor/client and not in page.php:
<html {{lang}}>
<title>{{title}}</title>
...
{{main-slider}}
JS and css are added through custom fields so they can be merged to one file.
Main slider post looks like this:
<div id="main-slider">{{main-slider-content}}</div>
JS and css can be provided to overrule page css or js and will be merged to one file.
And the main-slider-content is content that the editor can provide through a custom post provided by the programmer that will hold the editor's hand all the way and makes sure everything goes right.
Some of these fields can be set with custom fields values of the page (reverting to defaults if missing) some will be overwritten by the post (like language or title).
The type of sites that will be produced by this theme are used by small business owners who would like some web presence.
I have a couple of doubts about the design and hope someone with more experience with wordpress can shed some light on this.
When the editor/client edits a custom post like some slider content they cannot preview the item because that content is basically used on every page. Even if I find a way to list pages where the slider is used and show that one it won't show the new content until it's published. Previewing pages seems a bit complicated to implement.
It takes longer to generate the pages because content and sub content needs to be fetched from the database after parsing the content. I've tried to do this with DOMDocument before and used <div data-custom-content="main-slider"></div> but that is too slow so I'll try with regexp.
Because content isn't going to change that much I thought maybe APC cache the page after a first request and serve it from there. Delete the cache only when something is updated. On VPS the cache could be (probably would be) trashed when the site is inactive for a long time (which would be quite often). This means that requests take a long time to process when people try to view the pages.
Anyone with experience or helpful tips in this
[UPDATE]
I see that particular design and the html template will still have strong dependencies on each other. I am thinking now of trying out Twig. The benefit will be that re usable components are classes that can be added to the project and full content is controlled in the wordpress editor in a way that someone with no programming experience can still manage the content.
When data needed in the page is going to change a programmer is going to be needed though.
This is kind of what the Advanced Custom Fields Flexible Content system does, and the way you've styled your examples looks very like Smarty, a templating system that used to be very popular, and which is still used by a few systems like Prestashop.
In my experience, this removing the middleman kind of idea doesn't work. You either need a very extensive - and therefore bloated - initial theming system to flex to different projects, or you need a basic one which a developer will customise later - in which case the best you can achieve is moving the developer's role to a different phase of the project.
Overall, I think the best scope for this type of idea is for designers to learn a bit more code.

Migating from CakePHP to Drupal, functionality question

(I've posted this on the drupal forum too btw)
I'm converting the company websites to use Drupal, or at least trying to check that its going to be the best way forward. I have a background in PHP development, and I'm currently using the CakePHP framwork. I've built this site (not my design) and I can see how to replicate most of the functionality using Drupal, most likely using the CCK module.
http://preview.tinyurl.com/yk6u8mt
As you can see from the homepage:
A user chooses a country.
The country is passed using an ajax call to a script that decides which phone is best based on 'in country' network coverage.
A div is shown recommending the visitor the best phone for that country.
I'm wondering how to go about this in Drupal, I'm definitely not after a step by step guide, I just want to know if this kind of thing is possible with Drupal, and what approach to use.
If someone can help that would be superb. Thanks.
Okay, so you've got a path you're defining in hook_menu, which is where your form is being presented - or else you've got it set up as a webform in a node, that could work too.
Either way, in your form you're going to be using AHAH - check out http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah and http://drupal.org/node/348475 .
Basically, you're going to define another path in hook_menu that's of type MENU_CALLBACK, and which will receive the country as input, and then will return the div that you'll display on the screen.
One core example of AHAH that may be useful to you is where you're entering a password and it lets you know if the password is secure enough - check that out.
Edit: There's also some good examples at http://drupal.org/project/examples.
I would look into using CCK and views. you can set up filters for the views. If filters don't work, you have the ability to include php code. I have also successfully added jquery code in the header of a view through which I was then able to have my view filtered by what is typed in a text box.
Coming from CakePHP using Drupal is a pain in the a** - even more for developers.
It's application structure might be designed to ease extensibility but this only means you have a system to enable your own plugins and themes.
While modules are basically the M+C-part the themes are the V-part of an MVC-application. The problem is that this seperation is not very strict in Drupal - in fact you have to break it sometimes in order to make things work (e.g. you have to include a theme_mymodule_myfunction() into your module as default output which you then can override with your theme using mytheme_mymodule_myfunction() ) And don't even bother looking for classes ( see http://drupal.org/node/547518 ).
Also there is no real link from a module to a theme. On many occations this is a good thing as you can switch modules and themes seperatly without creating a problem. For application builders coming from CakePHP (or any other framework) you often feel a lack of "wholesomeness" - you create parts for a base software and have to live with it's drawbacks.
IMHO I wouldn't recommend this step. Drupal is fine if you have to manage a website and might add a few modules to add neccessary value (image gallery etc.) but I definetly don't recommend it as a base for a customized web-app.

Customizing GraffitiCMS

I downloaded GraffitiCMS the other day(now open source and free), and like a lot of what I see, but what I really want to use it for, is to add CMS capabilities to an existing asp.net database/application.
Without getting bogged down with all the details of my app, can someone give me the basic 'approach' that should be taken to add custom content to Graffiti; content that won't be a 'post'?
I've seen for example, how to add custom-widgets to Graffiti - basically inherit from the widget class, compile your dll and plop it into the correct directory and it becomes part of the system. Is there a way to do something similar for the main content areas?
For simplicity sake, pretend I have a non-graffiti database with gig's of data that I want to display on the website using standard asp.net grid's and forms. I realize I could just go in and hack apart the source code to integrate my existing app, but that is likely not the correct approach.
Not looking for a complete solution her, just a pointer and what areas to investigate...thanks.
If you check out the latest source of Graffiti (or the 1.3 branch that was recently created), support was added to put widgets anywhere you want on any page. There is a new chalk function - $macros.Widget - that provides you with this ability. Dan Hounshell wrote a blog post on how you can use this new functionality:
http://danhounshell.com/blog/graffiti-cms-1-3-add-a-widget-anywhere-in-a-view-with-new-widget-macro/
If you're looking for something different than that, just let me know - we're working to make Graffiti even better for situations just like you are currently in.
What we have done to be able to integrate Graffiti CMS with our current ASP.NET projects is to create a post in Graffiti called "hidden" and then with our standard .ASPX pages we call a class in our Render Override that pulls the "hidden" post (ie: site.com/hidden/) and uses the header and footer to wrap the Graffiti theme around our custom .ASPX page. We use some HTML comments in the "hidden" post to be able to parse the header and the footer. It is kind of a hack, but has worked out really well for us.
I think you're trying to put the cart before the horse - depending on the size and amount of functionality, I would be looking to rebuild it after learning the development platform of my CMS system of choice.
I'm pretty much in the same boat right now. I have avoided Graffiti because I have to learn "Chalk" (whatever that is) and Umbraco (using XSLT for layouts is retarded). So far, this leaves me with Sitefinity at the top of my list and Telerik have just pulled the free version!
I may end up grabbing a very basic CMS which is easier to customize. I know this doesn't directly answer your question, but it may give you some food for thought :-)

Resources