Ben Lobaugh Online

I think, therefore I am. I am, therefore I sail

Category: Jetpack Page 1 of 3

Remove Jetpack menu when not connected on a WordPress Multisite subsite (individual blog)


Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity, line: 7 in /srv/users/serverpilot/apps/benlobaughnet/public/blog/wp-content/plugins/auto-amazon-links/amazon.php on line 74

Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity, line: 7 in /srv/users/serverpilot/apps/benlobaughnet/public/blog/wp-content/plugins/auto-amazon-links/amazon.php on line 74

I run my own decent sized WordPress Multisite with the Jetpack plugin enabled at the network level. This allows me to manage at a high level view all the Jetpack connected blogs from a single Jetpack connection. Not all the blogs need to be running Jetpack, however because Jetpack is enabled network wide all blogs see the Jetpack menu item. Because I manage the connection I do not want individual admins seeing the Jetpack menu unless it is connected.

I whipped up the following code, which will remove the menu if Jetpack is not connected (yes, the code says “active”, poor wording choice in Jetpack itself) and individual blog admins are not allowed to manage their Jetpack connection.

add_action( 'admin_menu', function() {
    $jpms = Jetpack_Network::init();
    
    if( !Jetpack::is_active() && !$jpms->get_option( 'sub-site-connection-override' ) ) {
        remove_menu_page( 'jetpack' );
    }   
}, 1000 );

The Victoria Debacle

I am sitting in the dining room of a rustic wood cabin on Pender Island. Seated around me are six amazing people with a deep passion for WordPress. All morning the air has been buzzing with conversation on the future of WordPress and how to make it even more awesome. Everything was different just one day ago…

When planning for this meetup first got underway the faithful Zippety Doo Dah, my sailboat, was going to transport me to the house which is situated on the water and has a great dock. But a few days before, the weather started getting rough, I did not want my tiny ship to be tossed. Even with the courage of the fearless crew I did not want Zippey lost. So I pulled the plug, no pun intended, on the venture and made other plans to get to Victoria to catch the Pender Island ferry.

Friday at the respectable hour of 4am I awoke and forced myself to rush out of bed. I had almost a three hour drive to Port Angeles ahead of me! Though drowsy I pushed my body to the limits and made the Black Ball Ferry just as loading started. After victoriously landing in Victoria I messaged the group joining me to let them know I had arrived on Vancouver Island and after some food would drive north to the airport and meet them. The only response, “Ben, you know we get the house tomorrow right?”… I had departed my precious bed and country a day early!

All was not lost however. I have been to Victoria several times and enjoy the city. I grabbed a room in a hotel situated on a point of land that overlooks the boat traffic in two directions and then strolled around the waterfront oogling the boats. The sun was out and the weather great. I enjoyed the downtime during the daylight hours before launching into another adventure.

Creating a two way sync between a Github repository and Subversion

git_vs_svn

Another git <> svn post?

As many of you know I have been on a quest to get Jetpack core development moved from the WordPress.org Subversion (svn) repository to Github (git). As part of this process I setup an experimental Jetpack repository to see how synchronization works between git and svn. Lets just clear the air right now and say not well, not well at all. This is due to how git and svn each store their respective histories. But! I think I finally have it figure out.

Backfill

I wrote an article a couple months ago entitled Creating a synchronized Github fork of a WordPress.org Subversion plugin repository. This article is great (and still a recommended read) if you are only doing synchronization between the svn server and a local git repository, but fails miserably when adding in a remote git server such as Github (See note in Ch 8 of the git book). I was worried that true two way synchronization was not possible until I spoke with some helpful folks from Github and Zack Tollman (I.E. Git Master) who recommended I try a branch dedicated to the remote svn connection only instead of trying to mix it into trunk. I am happy to report that this setup has been working flawlessly for a couple months now. I have experienced zero conflicts when performing any syncs and now I want to show you how to set it up as well.

It should be noted that the sync is triggered by you on your local machine. This is not an automated process on Github’s servers, nor will any of the syncing information be available to anyone else who later clones the git repository.

Get your git

I will be utilizing the Jetpack repository I setup on Github for the examples going forward in this tutorial, so the first thing to do is setup yourself a repository on Github where this project will live and then clone it down to your local machine.

git clone git@github.com:blobaugh/jetpack.git

or for those of you not using ssh keys with Github (you really should)

git clone https://github.com/blobaugh/jetpack.git

(Sidenote: Ironically you can also checkout from Github via svn with the https address…)

You will use trunk and development branches here as normal. Feel free to do all the pushes and pulls to Github that you desire, however do not hook up trunk or any development branches to the Subversion repository!

Setup an svn tracking branch

The next step is to create a branch that will only be used to setup a remote connection to the Subversion server. You will never do any development changes directly in this branch. If you do you will most likely encounter severe issues due to the incompatible histories of both systems. Instead you will be using git’s merging features between branches.

git branch --no-track svnsync
git svn init -s http://plugins.svn.wordpress.org/jetpack
git svn fetch
git reset --hard remotes/trunk

(Sidenote: If you are syncing also author profiles you can add

--authors-file svn-authors.txt

to the fetch command. I will update this tutorial with details on the author file later)

 Do your business

You are now all setup to begin developing your amazing whatever with full confidence that changes made to the git or svn side can and will safely be reflected back to each other. But wait! Keep reading now to find out the tricks to make the sync work after you have created those amazing new additions to your project.

Merge changes back from svn into Github trunk

First all changes from svn are going to be merged locally and staged to be pushed out to the Github repository.

git checkout svnsync
git svn rebase
git checkout master
git merge svnsync
git push origin master

Merge changes from Github trunk into svn

Now going the other direction. This is a bit more complicated than pulling in from svn, but make sure you follow all the steps or you will get nasty errors with the sync. Keep in mind the –no-ff on the merge is very important to include. We also want to make sure everything is fully updated from both Github and the svn server before performing the push to svn.

git checkout master
git pull origin master
git checkout svnsync
git svn rebase
git merge --no-ff master
git commit
git svn dcommit

The order of the commit and dcommit is important here. Switch them and the histories will conflict.

Drink Scotch

This is the happy point when everything is working lovely and you get to drink Scotch to celebrate!

And if something went wrong and you are freaking out an anxiously scratching your head I also recommend Scotch 🙂

Resources

Here are a few resources that helped in writing this tutorial:

Episode 64 of WPwatercooler, featuring Jetpack and Me!

My very first appearance on WPwatercooler happened this week with Episode 64 all about the Love and Hate of Jetpack. My colleague George Stephanis was also on the show, which was lucky for me cause I was not feeling too great. He did most of the heavy lifting in representation of Jetpack. Thanks George!

Jetpack Ocean Party!

Today was our fun day so we had a Jetpack Ocean Party!

1459255_4990710265950_359461606_n

After a bus ride where we all thought we were traveling around the entire island we finally arrived at the big catamaran that was going to take us out on our snorkeling tour.

DCIM100GOPRO

We went to two different island to snorkel. The snorkeling and hanging out was great, though the water was not very clear and the coral itself was not that interesting. There were several neat fish that I saw, but mostly due to the water clarity we were unable to get good photos with Ryan’s GoPro2 ( Sidenote: Adding the GoPro to my shopping list if anyone feels generous and wants to get me one ). On the way back in I met Rocket v3, more commonly known as Trisha. So much heartbreak this week ;).

When we got back to the house we went down to the beach and dove into the waves. It was then that I realized how exhausted my body was from snorkeling for several hours. Swimming against the waves and current was an amazing workout.

Anyways, here are some photos from the time. Videos will be beneath the photos.

General day from my iPhone

First island with GoPro2

Second island with GoPro2

Page 1 of 3