Category Archives: PHP

How-to for PHP

Creating a WordPress Child Theme

Overview

WordPress LogoSave yourself some heartburn, do not modify WordPress templates directly … create child templates. Creating a child template will allow you to update a theme without having to re-work it to include your change.

To create a child theme, you need to do the following:

  • Create a child theme directory
  • Place a new style.css file in your child theme directory
  • Add a functions.php file to the child theme directory
  • Add copies of files you plan to modify in the new child theme directory

Create a child theme directory

Go tot he themes diretory (wp-content/themes), create a subdirectory with the name othe original theme, but, append “-child’ to the directory name. Example, if you want a child them for the twentyfifteen theme, create a subdirectory twentyfifteen-child.

In the twentyfifteen-child directory, create a file style.css. In the style.css file, you must have the following minimum header.


/*
 Theme Name:   Western Way Realty
 Theme URI:    http://example.com/western-way-realty/
 Description:  This is a Child Theme of twentyfifteen for the Nomad Realty
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

 

When creating the header for the style.css file, include the

  • Them Name: followed by the name of your new child theme
  • Theme URI: followed by the location of updates for the theme
  • Description: followed by the description of the template and remember to reference the name of the parent theme to assure user remembers to include the parent theam.
  • Author: followed by your name (or the name of the developer of the new child template)
  • Author URI: followed by the URI of the authors website.
  • Template: followed by the name of the parent template
  • Version: followed by the version number you want for the child template
  • License: followed by the software license that is used to release this template
  • License URI: followed by the address of a copy of the release license.

Following the style.css header, you may now add any new CSS that will be needed in your theme.

Create a function.php file

In the child theme directory, create a file function.php. The original theme function will provide all functions you need, but, this function.php can be used to override the function.php function or to include new function.php content for the child theme.

At minimum, the functions.php file should include the following:


    add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
    function theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array('parent-style')
    );
}

 

The above code assure that the parent style.css file is loaded, and it assure that the new style.css file is loaded for the new theme.

With the creation of the functions.php file in your child directory, you are ready to go…

Keep Going

Keep going creating your new child theme. Add new child themes functions to the new functions.php. Add the new CSS content to the new style.css file. If you need to modify other files, such as header.php, footer.php, template.php or any other file … copy it to your new child theme directory and make your mods in the new child themes directory.

Zen Cart .. (35) error:14094410:SSL routines Error Message

Warning: If you are running Zen Cart, use PayPal and have not upgraded to Zen Cart 1.5.4, you need to make some changes. PayPal changed handling on for their transaction interface API to account for hackability of the SSLv3. Due to the POODLE security problem, SSLv3 is nolonger accepted by PayPal. Many people have adjusted, but, for those of your with Zen Cart that have not fixed the problem yet, be aware you have a problem.

This SSLv3 problem has been fixed in Zen Cart 1.5.4, but, many people have yet to move to that revision. If you have not upgraded, you are being rejected from PayPal transactions with a message similar to “(35) error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure.” If you are receiving this message, you will need to modify the all PHP files that contain a refer to SSLVERSION. Do a search for references to SSLVERSION, comment out all locations that look like this:

    CURLOPT_SSLVERSION => 3
         or 
    curl_setopt ($ch, CURLOPT_SSLVERSION, 3);

Your resulting code at those locations would look like this:

   //  CURLOPT_SSLVERSION => 3
         or 
   //  curl_setopt ($ch, CURLOPT_SSLVERSION, 3);

Among other locations you may find in your search, your search should find locations to change in the following files.

  • includes/modules/payment/paypal/paypal_curl.php
  • includes/modules/payment/linkpoint_api/class.linkpoint_api.php
  • includes/modules/payment/authorizenet_echeck.php
  • includes/modules/payment/authorizenet_aim.php
  • extras/curltester.php

Enjoy your day …

WordPress: Changing Maximum Upload Size

Using WordPress to upload videos (or other files), it may turn out that you need to upload a file larger than the maximum limit set by WordPress. This should no be a significant, you can increase the size of the allowed upload file. To increase the upload size, you must adjust some or all the following PHP variables:

  • WP_MEMORY_LIMIT
  • upload_max_filesize
  • post_max_size
  • max_execution_time

Must and may changes are as following. To increase the upload size, you must increase the upload_max_filesize and post_max_size. If the file is large enough, you may need to increase the size for memory_limit, max_execution_time and max_input_time.

The changes may be made in two locations. They may be made in your php.ini file or your .htaccess file. You may not change them by modifying your wp_config.php file adding an ini_set. Using ini_set in wp_config.php might be your first instinct, but, that will not work.

To keep the change more localized, modify the .htaccess file with the following code (changing the upload preference size as needed for your situation)


    <IfModule mod_php5.c>
        php_value memory_limit 64M
        php_value upload_max_filesize 64M
        php_value post_max_size 64M
        php_value max_execution_time 600
        php_value max_input_time 600
    </IfModule>

If you prefer to change php.ini, you can add the following to th php.ini file as needed in your situation


    memory_limit = 64M
    upload_max_filesize = 64M
    post_max_size = 64M
    max_execution_time = 600
    max_input_time = 600

Create a New WP Page Template

Creating a new WP Page or Post Template is easy. It is nice that templates to gallerys, video pages, left templates, right templates, etc are currently available. But, from time to time I like to add a new template that has special CSS attached, or uses the title, content and featured image is a different way

This article talks about the way to add a new wordpress page or post template to your list of template selections.

To create a new template:

  • Decide on a name for your new template.

    The template name must have a special format, the options are as follows:

    • page-{slug}.php
    • page-{ID}.php
    • page-{general description}.php

    The first two naming conventions are used for formatting a specific article. If you have created a page or post and you would like that particular page or post to have a special format, you will create a new file that uses the slug or ID of the page to force wordpress to use the new template on that page/post only. These templates to do not show up in the template selection list, they simply format the specific pages.

    The third naming convention is not mandatory, but, is convenient. The third naming convention is used for a template that you would like to see in the template selection list as you create the new page or post. {general description} should be selected to reflect the label you would like seen in the drop down list of the templates. If you are creating a special format template for creation of landing pages, you might use the general description “landing.” If your description has more than one word (ex: my landings) use a dash(-) in place of spaces in your phrase.

    In our example, we will create a new template called “page-landing.php.”

  • Copy an existing template that is similar to the template you need. If you do not want to start from scratch creating the template, there are several files available for you to start with as a baseline for your new template. You will copy it and rename it to your selected new name. To determine what baselines are available to you, go to your theme directory and look down the list to all the files that have the format page-XXXX.php. Any of these and the file page.php can be used as a baseline. For our example, we will copy page.php to the file named page-landing.php.
  • Modify the existing template.

    To create the new general template, you need only add 3 lines at the very top of the file. At the top of the new file page-landing.php, adjust to say:

    
    
        <?php
        /*
        Template Name: Page: landing    
        */
    
           

    The “Template name: ” label may be followed by

    • Page: {description}
    • Post: {description} or
    • {description}

    Once you are done adding this {description}, it will be added to the list of options available in your templates list and it can be selected from your new dropdown list of template options. Go ahead, modify your template and expect to be able to call on this template to help you whenever you need the new template.

  • Your ready to go. Go ahead and create your next post or page with your new format.

New Versions of WordPress Abort MORE

WordPress is getting to be more and more a nuisance to debug in dreamweaver. Loading WordPress in Dreamweaver causes an immediate shutting of Dreamweaver. This was happening in the past because of the inclusion of the files dashicons.css and dashicons.min.css in the includes/css directory. They were not needed for testing and typical development, so, they could simply be deleted. dashicons.css and dashicons.min.css offer simple use CSS icons that are used primarily in the admin area, though they could be used in any of your development. Deleting dashicons.css and dashicons.min.css left the admin area without icons, but, the icon text descriptions remained and you could live with for preliminary testing. However, now we are back to the same crash problem.

More oversize strings have been added to other files in WordPress and they cause Dreamweaver to exhaust its workspace memory and crash. . Now, to do debugging in Dreamweaver, the following files and directories must be deleted from WordPress:

  • wp-includes/css/dashicons.css
  • wp-includes/css/dashicons.min.css
  • wp-content/themestwentyfourteen/genericons (full directory)
  • wp-content/themestwentythirteen/genericons (full directory)
  • uploads/am_assets

Deleting these files/directories allow debugging in Dreamweaver. Again when testing, the situation relates to availabiliity of CSS icons and assets … for the development. These deletions increase the number of items that vanish in your use of wordpress, but, maybe you can live knowing that in preliminary debug icons and assets will be missing, but, available in an integration test. If you understand what you are deleting and what you can expect from these deletions, no problem. When you load a full version of WordPress in a full installation all icon functionality returns, but, the nuisance level of development is increasing. Someday, we will want to upgrade your Dreamweaver or start using NetBeans or Eclipse to avoid the problem.

Personally, I find Eclipse or NetBeans will be a reasonably good replacement for Dreamweaver. They are free and have some very nice features. In some cases, they have nicer features than Dreamweaver, though they do miss a few features I do like in Dreamweaver. Their big problem is they are harder to install and interface with the test server, but, if Dreamweaver continues to be a nuisance, they will be far better alternative.