Restricting PluginDocumentSettingPanel by post type

Now that the PluginDocumentSettingPanel is in WordPress core, we can add our own panels to the Document Settings panel using the registerPlugin function.

const { registerPlugin } = wp.plugins;
const { PluginDocumentSettingPanel } = wp.editPost;

const MyCustomSideBarPanel = () => (
    <PluginDocumentSettingPanel
        name="my-custom-panel"
        title="My Custom Panel"
    >
        Hello, World!
    </PluginDocumentSettingPanel>
);
registerPlugin( 'my-custom-panel', {render: MyCustomSideBarPanel } );

The above code will insert a new Panel in the Document Sidebar with the title of My Custom Panel ” and will display “Hello, World!” as it’s content. If we want this panel to appear on every post type registered, then we’re done but what if we want to restrict this panel to just a single post type?

Continue reading “Restricting PluginDocumentSettingPanel by post type”

Same WordPress plugin, new name

A little while ago, I created a plugin called Suspend Transients. It is a helpful tool that allows developers to bypass get_transient()  calls on any page by clicking a button on the admin bar.

I felt that the name was not accurate so I have renamed it and it is now available for download on WordPress.org as Bypass Transients.

Development is happening on GitHub and pull requests are welcome along with any and all feedback in the comments below!

Thanks Adam!

WordPress 4.7 was just released and it marks the sixth release in a row that I have been lucky enough to contribute to.

Contributing to WordPress core has always been a personal goal for me and while I had made attempts in the past, it wasn’t until I joined 10up that I was finally able to contribute back to the open source project that pays my bills.

Contributing to WordPress Core is not hard in and of itself but what can be hard is the ramp up. WordPress is 13 years old, that’s a lot of project history to grok! Besides that, there is trac and the technical side that a new contributor has to figure out before they can even get to place to start writing code.

Having someone to help you navigate the waters of WordPress core contribution is invaluable. For me, that person was ( and still is ) Adam Silverstein, a friend,  and fellow 10upper. Without his help, guidance and patience, I would probably still be trying to figure out how to get someone to look at my tickets 🙂

Adam was recently given commit access to WordPress Core and I wanted to congratulate and thank him for everything he has done for me personally and for the larger WordPress community.

 

Setting up Unit Testing for WordPress Core

Recently I was running into issues with VVV running some units tests for AJAX. I was not able to remedy the issue so I decided to create a testing environment from the SVN repo directly.

I went to the page on the codex and while the information there was great, part of the instructions are to setup a different database for your tests but not how to get mysql setup and ready for anything to connect to it.

After a bit of digging around I found a simple approach for setting up a test suite for WordPress core unit tests. This setup does not account for viewing WordPress in a browser it was really only meant for unit testing but you could easily set that up as well if required.

Using homebrew, install mysql

brew install mysql

Once installed, start the server

mysql.server start

Once the server has started you can login using the default user (root) and password (blank)

mysql -u root -p

You may be prompted for a password  if so, just hit enter.

Now you can create the tables as needed. There are two commands here because we need a database for WordPress regular use and one for unit testing because the test suite will drop all of the tables in the database each time it’s run.

CREATE DATABASE wp-unit-tests;
CREATE DATABASE wp-normal;

That’s it! Now your databases are all setup to use.

Next, checkout the WordPress repo into your user folder and change to that directory

svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
$ cd wordpress-develop

Now edit the wp-config.php and wp-test-config.php adding in the appropriate database connection info for each.

I found that I needed to set the DB_HOST constant to 127.0.0.1 instead of localhost to have the connection work.

If everything is setup correctly, you can run the unit test suite from inside the root of the core repo.

phpunit

Once you’re done with your testing you stop the mysql server as it can cause conflicts with other tools that use their own mysql installations.

mysql.server stop

That’s it! Happy unit testing!

 

First WordPress core props!

It was a very simple patch, just removing some code that is no longer needed, but now that ticket #31485 has been committed, I will have contributor props for WordPress 4.2!

Update: 4.2 was released today and I am very happy to have played a (small) part in it!

Photos or it didn’t happen!

 

Change the WordPress post updated messages

Sometimes it is necessary to modify or remove the default WordPress post updated messages that are displayed when making changes to a Post in WordPress.

One example is when you are creating a custom post type that does not have a permalink. When you save a draft, publish or update a published post, you are presented with messaging that includes a link to the post – which in that case will take the user to a 404 page. Continue reading “Change the WordPress post updated messages”

Custom post types with no permalinks

When I was at WordCamp Ottawa this year, I was asked a question about how to create custom post types without generating permalinks. This is actually something I do a lot of as I am creating internal content types that are not meant to be viewed individually at their own url.

The snippet below will register the post type and you’ll notice that there is no Permalink line below the title. Continue reading “Custom post types with no permalinks”

Creating a skinnable WordPress widget

Building custom widgets is fun, rebuilding them because we need to change the way it looks is not. With that in mind, lets build a skinnable WordPress widget that separates how it looks from what it does. For the purposes of this tutorial, I am assuming that you are comfortable creating a Widget and working with the API. Please refer to the Widget API as needed. Continue reading “Creating a skinnable WordPress widget”

WordPress Stuck In Maintenance Mode

If you ever have an automatic update fail sometimes your WordPress install can get stuck in maintenance mode. I just had this happen to me and was able to find a quick solution.

Log into your server via FTP and look for a .maintenance file, delete it and you should be up and running again.