WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Mar 04 2014

Setting Up a Local Environment via XAMPP: Creating a Database via phpMyAdmin

4. Create a New Database

After you’ve installed XAMPP, run it by opening a browser and going to localhost, which will take you to the splash page.
XAMPP Splash

Click on your preferred language. It should take you to the start page, http://localhost/xampp/.
XAMPP Home

Now click on phpMyAdmin at the bottom left.
XAMPP phpMyAdmin

In the phpMyAdmin page, create a new database by clicking on Databases at the top.
XAMPP phpMyAdmin Databases

Since this is local anything will do (eg. prefix_wordpress). However, you want a more complicated database name than this to protect yourself from SQL injection on the internet. Adding a prefix will create folders to help with the organization.
XAMPP phpMyAdmin Create Database 1
XAMPP phpMyAdmin Create Database 2
XAMPP phpMyAdmin Result

Now go to phpMyAdmin, and create a new database (eg. prefix_wordpress) by typing in your database name (e.g. wordpress) and pressing CREATE.

Written by Travis Smith · Categorized: WordPress

Mar 03 2014

Setting Up a Local Environment via XAMPP: Installing XAMPP

Before You Get Started

WordPress needs PHP and mySQL to run. This tutorial installs via XAMPP, not WAMP or MAMP (Mac), so I will not be going into any details regarding WAMP or MAMP, but some of the things will apply to them as well.

1. Install XAMPP, a Local Server

In order to run any PHP/database application on a local computer, you need a local host (ie. Apache + MySQL). So go and download the most recent version of XAMPP or the version from this tutorial is XAMPP 1.8.3 (Sourceforge Old Versions, Windows Version, 128MB).

[browser-shot width="600" url="http://www.apachefriends.org/index.html"]

Setup XAMPP
Setup XAMPP Modules
Setup XAMPP Location

I personally disable BitNami, but feel free to include it.
Setup XAMPP Disable BitNami
Setup XAMPP Ready to Install
Setup XAMPP Installing
Setup XAMPP COMPLETED!
Setup XAMPP COMPLETED!

Once installed, move to the next step. You may go ahead and launch the Control Panel, but do not do anything yet. First we must configure the PHP modules to ensure that we have everything set as we need.

Written by Travis Smith · Categorized: WordPress

Mar 01 2014

Plugin Uninstall: How to Delete Terms & Taxonomies from WordPress Database

Many developers do not consider what they should do when a person deactivates a plugin (like flush_rewrite_rules()), much less what to do with the data the plugin created, much of which is useless. In my opinion, this is partly because creating an extra uninstall.php file is a bit problematic to test over and over.

So, in this snippet, here is how you can delete ALL the terms and the associated taxonomy when a plugin is deleted by a user. First create a file called uninstall.php which appears at the root of the plugin. Then add this code:

<?php
/** Delete All the Taxonomies */
foreach ( array( 'my_first_custom_tax', 'my_second_custom_tax', 'my_third_custom_tax', ) as $taxonomy ) {
// Prepare & excecute SQL, Delete Terms
$wpdb->get_results( $wpdb->prepare( "DELETE t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s')", $taxonomy ) );
// Delete Taxonomy
$wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $taxonomy ), array( '%s' ) );
}
view raw uninstall-terms-taxonomy-1.php hosted with ❤ by GitHub

Sometimes, however, you may need to do something else between the code. For example, you may have custom term meta within the options table that would need to be deleted as well.

<?php
/** Delete All the Taxonomies */
foreach ( array( 'my_first_custom_tax', 'my_second_custom_tax', 'my_third_custom_tax', ) as $taxonomy ) {
// Prepare & excecute SQL
$terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s') ORDER BY t.name ASC", $taxonomy ) );
// Delete Terms
if ( $terms ) {
foreach ( $terms as $term ) {
$wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $term->term_taxonomy_id ) );
$wpdb->delete( $wpdb->terms, array( 'term_id' => $term->term_id ) );
delete_option( 'prefix_' . $taxonomy->slug . '_option_name' );
}
}
// Delete Taxonomy
$wpdb->delete( $wpdb->term_taxonomy, array( 'taxonomy' => $taxonomy ), array( '%s' ) );
}
view raw uninstall-terms-taxonomy-2.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

Feb 26 2014

Beginner’s Guide to Google Webmaster Tools: 12 Ways to Grow Your Blog

Google Webmaster Tools How To

Written by Travis Smith · Categorized: WordPress

Feb 25 2014

Deactivate Your Plugin Extension with the Extended Plugin

In the previous post, Extending or Modifying a Plugin, in this two part series, I wrote about modifying by extending an existing plugin using a plugin. This left us with the following question:

How do I deactivate my plugin if the extended plugin was deactivated?

This snippet will allow you to deactivate your extended plugin when the extended plugin deactivates.

<?php
add_action( 'update_option_active_sitewide_plugins', 'dpse_deactivate_self', 10, 2 );
add_action( 'update_option_active_plugins', 'dpse_deactivate_self', 10, 2 );
/**
* Deactivate ourself if Addthis is deactivated.
*/
function dpse_deactivate_self( $plugin, $network_deactivating ) {
if ( !is_plugin_active( 'addthis/addthis_social_widget.php' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ), true );
}
}
view raw display-posts-deactivate.php hosted with ❤ by GitHub

Picking up from the previous post, in the example below, there is a code snippet to customize Display Posts Shortcode. So, if the client decides to deactivate Display Posts Shortcode, then this plugin will deactivate itself automagically.

Yes, it is strange that I am hooking into the updated_option hook. One would think that this could be done with the deactivated_plugin hook, but it cannot since at the time of this post either the documentation (ticket #27189) is wrong or the action occurs at the wrong place (ticket #27189, see also #20241).

Full Extended Plugin

<?php
/**
* Display Posts Shortcode Extension Plugin
*
* @package DT_Display_Posts
* @author Travis Smith <[email protected]>
* @license GPL-2.0+
* @link http://wpsmith.net
* @link http://wordpress.org/plugins/display-posts-shortcode/
* @copyright 2014 Travis Smith
*
* @wordpress-plugin
* Plugin Name: Display Posts Shortcode - My Extension
* Plugin URI: http://www.wpsmith.net
* Description: Extends Display Posts Shortcode
* Version: 1.0.0
* Author: Travis Smith
* Author URI: http://www.wpsmith.net
* Text Domain: displayposts-ext
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
add_filter( 'display_posts_shortcode_args', 'dpse_shortcode_exclude_posts', 10, 2 );
/**
* Add "not_in" arg to Display Posts Shortcode
*
* @since 1.0.0
*
* @param array $args Default Display Posts Shortcode args.
* @param array $atts Original shortcode attributes.
* @return array $args Modified Display Posts Shortcode args.
*/
function dpse_shortcode_exclude_posts( $args, $atts ) {
if( isset( $atts['not_in'] ) ) {
$args['post__not_in'] = explode( ',', $atts['not_in'] );
}
return $args;
}
add_action( 'update_option_active_sitewide_plugins', 'dpse_deactivate_self', 10, 2 );
add_action( 'update_option_active_plugins', 'dpse_deactivate_self', 10, 2 );
/**
* Deactivate ourself if Addthis is deactivated.
*/
function dpse_deactivate_self( $plugin, $network_deactivating ) {
if ( !is_plugin_active( 'display-posts-shortcode/display-posts-shortcode.php' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ), true );
}
}
view raw display-posts-shortcode-ext-plugin.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 25
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in