Archive for the ‘ Plugins ’ Category

Find tables without primary keys

Some plugins create tables in MYSQL without primary keys which may break exporting and importing actions.

We can identify where exactly with this SQL script:

SELECT
t.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES AS t
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k
ON (
t.TABLE_NAME = k.TABLE_NAME
AND k.CONSTRAINT_SCHEMA = t.TABLE_SCHEMA
AND k.constraint_name = 'PRIMARY'
)
WHERE
t.TABLE_SCHEMA NOT IN ('information_schema', 'performance_schema', 'mysql', 'sys')
AND t.TABLE_SCHEMA = 'database name' -- put database name here
AND k.constraint_name IS NULL;

WordPress Display Posts Shortcodes

Display Arguments

Arguments are used to customise how the posts are displayed. Below is a list of common arguments you can add to your Display Posts shortcode and examples of how the shortcode should look with the argument added.

author
Specify the post author
Default: empty
Example:

[display-posts author="bill"]

category
Specify the category slug (or comma separated list of category slugs). View this shortcode in action on this example site.
Default: empty
Example:

[display-posts category="fishing,hiking"]

date_format
Specify the date format used when include_date is true. See Formatting Date and Time on the Codex for more information.
Default: ‘(n/j/Y)’
Example:

[display-posts include_date="true" date_format="F j, Y"]

id
Specify a specific post ID (or multiple post IDs) to display.
Default: empty
Example:

[display-posts id="9, 10"]

image_size
Specify an image size for displaying the featured image, if the post has one. The image_size can be set to thumbnail, medium, large (all controlled from Settings > Media).
Default: empty
Example:

[display-posts image_size="thumbnail"]

If you’re using a theme that supports Content Options, and have it set to not show featured images on Pages, the image_size argument will also have no effect on shortcodes used on a page on the site – featured images will not show for any posts added via the shortcode even if the shortcode says they should be shown.

include_content
Include the full post content after the title.
Default: empty
Example:

[display-posts include_content="true"]

include_date
Include the post’s date after the post title. The default format is (7/30/12), but this can be customized using the ‘date_format’ parameter.
Default: empty
Example:

[display-posts include_date="true"]

include_excerpt
Include the post’s excerpt after the title (and date if provided).
Default: empty
Example:

[display-posts include_excerpt="true"]

offset
The number of posts to pass over
Default: 0
Example:

[display-posts offset="3"]

order
Specify whether posts are ordered in descending order (DESC) or ascending order (ASC).
Default: DESC
Example:

[display-posts order="ASC"]

orderby
Specify what the posts are ordered by. See the available parameters here.
Default: date
Example:

[display-posts orderby="title"]

portfolio_type
If you are using the Portfolio post type, use this to get items from a specific portfolio type.

post_parent
Display the pages that are a child of a certain page. You can either specify an ID or ‘current’, which displays the children of the current page.
Default: empty
Example:

[display-posts post_type="page" post_parent="8"]

post_status
Show posts associated with a certain post status
Default: publish
Example:

[display-posts post_status="publish, future"]

post_type
Specify which post type to use. You can use a default one (post or page).
Default: post
Example:

[display-posts post_type="page"]

posts_per_page
How many posts to display.
Default: 10
Example:

[display-posts posts_per_page="5"]

tag
Specify the tag slug (or comma separated list of tag slugs)
Default: empty
Example:

[display-posts tag="tag1, tag2"]

taxonomy, tax_term, and tax_operator
Use these parameters to do advanced taxonomy queries. Use ‘taxonomy’ for the taxonomy you’d like to query, ‘tax_term’ for the term slug (or terms) you’d like to include, and ‘operator’ to change how the query uses those terms (most likely this field will not be needed).
Default: ‘taxonomy’ = empty , ‘tax_term’ = empty , ‘tax_operator’ = ‘IN’
Example:

[display-posts taxonomy="color" tax_term="blue, green"]

wrapper
What type of HTML should be used to display the listings. It can be an unordered list (ul), ordered list (ol), or divs (div) which you can then style yourself.
Default: ul
Example:

[display-posts wrapper="ol"]

Original links:

Cloudflare CSRF Token Error

When installing a new website we had errors when trying to make settings for Cloudflare. The error message said:

To fix this we had to disable Wordfence by commenting out its lines in the .htaccess file:

# Wordfence WAF
#
#        php_value auto_prepend_file '/var/www/html/sites/events/summit2018/wordfence-waf.php'
#

Once the connection was made, you can uncomment the lines above in the .htaccess file.

Changing the default (root) folder in WP File Manager plugin

WordPress File Manager is a great plugin for managing sub-folders and other files in the back-end.
However, the default directory is set to the site root. If you dont want your users to have access to your WP installation files, it’s best to change this to a different folder.

To change this setting edit the plugin files (shortcut here)

'path'	=> ABSPATH.'/wp-content/uploads/',	// path to files (REQUIRED)
'URL'	=> site_url().'/wp-content/uploads/',	// URL to files  (REQUIRED)

Like this:

file-manager

Installing Yoast breadcrumbs

<?php if ( function_exists(‘yoast_breadcrumb’) ) {yoast_breadcrumb(‘<p id=”breadcrumbs”>’,'</p>’);} ?>

http://kb.yoast.com/article/245-implement-wordpress-seo-breadcrumbs

Allowing Filemanager in User Role Editor

I assign the role of Editor to the staff editing the event websites. By default this limits their ability to use Filemanager. And the usual check boxes don’t work so we have to switch the interface to “Deprecated mode” and check all the “Level_#” boxes.

user-role-editor-filemanager

Exhibitor Press Release Uploads

There are three components to the system:

 

A) The exhibitor upload page

The first thing we need to do is build the form using the “WordPress Form Manager” plugin.
We create a form with the following fields: “Company name”, “Document title” and “Select document”. We also add a note field to display additional information about accepted file formats and file size, etc. Pay attention to the upload document section as to restrict the document types.

We also add a “Private Field” at the bottom of the “Form extra” tab. This is what our administrator will use to approve each press release.

Once you have created the form, add it to the exhibitor upload page with the following shortcode format:
[form form-XYZ]

 

B) The public listing page

We include a simple PHP script into the WordPress page to pull data off the database. The code I used can be obtained here.

To summarise, the script will need to be modified in the following places:

  1. Database name
  2. Form table
  3. User (an account with read-only access just to the form table was created for this application)
  4. Password
  5. The blob variables in the loop

 

C) Administration page

The administrator logs into WordPress and navigates to the Submission Data tab of the form being used.
Using the checkboxes and the “Edit selected” function from the dropdown list of actions, the admin can edit…

form-edit

and approve each press release.

form-approve

Bulk show/hide pages in WordPress

We use the plugin Exclude Pages to show or hide pages in the navigation of our WordPress sites.

exclude-1
It’s very useful, but if you suddenly need to show or hide a lot of pages, it becomes tedious and a waste of time to do it through the WordPress backend.

That’s why I looked at how to bulk edit this in the database directly. Start by locating the correct table in MySQL:

exclude-2

Then add or remove page ids as needed. (Note: The numbers that appear here are the pages that are hidden from the user)

Google Analyticator

I have installed the WordPress plugin “Google Analyticator” on all the WordPress-based websites.
However, for those that have the “EWEA Master Code” installed, I needed to edit the plugin code.

<script type="text/javascript">
var _gaq = _gaq || [];

// This website code here:
_gaq.push(['_setAccount', '<?php echo $uid; ?>']);
<?php if ($need_to_annon == '1' ): ?>
_gaq.push(['_gat._anonymizeIp']);
<?php endif; ?>
<?php

    # Add any tracking code before the trackPageview
    do_action('google_analyticator_extra_js_before');
    if ( '' != $extra )
            echo "$extra\n";

    # Add the track pageview function
    echo "_gaq.push(['_trackPageview']);\n\n";

    # Disable page tracking if admin is logged in
    if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
            echo "_gaq.push(['_setCustomVar', 'admin']);\n";

    # Add any tracking code after the trackPageview
    do_action('google_analyticator_extra_js_after');
    if ( '' != $extra_after )
            echo "$extra_after\n";

    # Add the final section of the tracking code
    ?>

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Now we add the EWEA Master Code in the plugin settings area:

EWEA Master

For copying/pasting:

// EWEA's master code here:
  _gaq.push(['_setAccount', 'UA-4609386-40']);
  _gaq.push(["_setDomainName", "none"]);
  _gaq.push(["_setAllowLinker", true]);
  _gaq.push(["_trackPageview"]);

 

Youtube Video Gallery plugin

This is what I implemented on EWEA OFFSHORE 2013 Video Archive page:

http://wordpress.org/extend/plugins/youtube-channel-gallery/

http://www.ewea.org/offshore2013/media-and-press/video-archive/