Archive for the ‘ CMS ’ 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:

Change a WordPress user from editor to admin in PhpMyAdmin

A web consulting agency recently took over my admin account essentially locking me out of a website. Fortunately, if you have access to the database via a tool like PhpMyAdmin, you can easily get back in.

First open the wp_users table for the WordPress you wish to access. Look for your account and note down the user ID number:

user-ID

Note: If you don’t have an existing account, you will need to create a new one. (You can check this article on how to do it.)

Next, access the wp_usermeta table and look for your ID number.

In the meta_key field wp_capabilities,
add this meta_valuea:1:{s:13:"administrator";s:1:"1";}

Save and exit and you should now be an administrator again.

More infohttps://themeisle.com/blog/new-wordpress-admin-user/

Query another DB from within WordPress

Add this line to change the default DB to another one:

$wpdb = new wpdb('username','password','database','localhost');

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

Disabling automatic updates in WordPress

Configuration via wp-config.php

Using wp-config.php, automatic updates can be disabled completely, and core updates can be disabled or configured based on update type.

Constant to Disable All Updates

The core developers made a conscious decision to enable automatic updates for minor releases and translation files out of the box. Going forward, this will be one of the best ways to guarantee your site stays up to date and secure and, as such, disabling these updates is strongly discouraged.

To completely disable all types of automatic updates, core or otherwise, add the following to your wp-config.php file:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

Constant to Configure Core Updates

To enable automatic updates for major releases or development purposes, the place to start is with the WP_AUTO_UPDATE_CORE constant. Defining this constant one of three ways allows you to blanket-enable, or blanket-disable several types of core updates at once.

define( 'WP_AUTO_UPDATE_CORE', false );

WP_AUTO_UPDATE_CORE can be defined with one of three values, each producing a different behavior:

EWEA Photolibrary config file

EWEA ResourceSpace config.php file. This information is key for decrypting the photo database.

<?php
###############################
## ResourceSpace
## Local Configuration Script
###############################

# All custom settings should be entered in this file.
# Options may be copied from config.default.php and configured here.

# MySQL database settings
$mysql_server   = 'localhost';
$mysql_username = 'photolib_user';
$mysql_password = '5A5wdpqG';
$mysql_db       = 'photolibrary_test';

$mysql_bin_path = '/usr/bin';

# Base URL of the installation
$baseurl = 'http://intranet/photolibrary';

# Email settings
$email_from   = '[email protected]';
$email_notify = '[email protected]';

$spider_password  = 'uqe7ySEWEvan';
$scramble_key     = 'uXeXADaqYZat';

$api_scramble_key = 'aBeGA2yBA4ed';

# Paths
$imagemagick_path      = '/usr/bin';
$ghostscript_path      = '/usr/bin';
$ftp_server            = 'my.ftp.server';
$ftp_username          = 'my_username';
$ftp_password          = 'my_password';
$ftp_defaultfolder     = 'temp/';
$thumbs_display_fields = array(8,3);
$list_display_fields   = array(8,3,12);
$sort_fields           = array(12);

EWEA navigation script

This solution is to create a local HTML file from the dynamic www.ewea.org/navigation-file generated by Typo3, that can be rsync’d to other servers so that they may include it in their templates as local files, speeding up the page creation process (and bypassing a huge latency issue we had with the EWEA 2015 programme pages).

#!/bin/sh
curl -L -o /var/www/html/sites/www.ewea.org/navigation http://www.ewea.org/navigation-file
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/
rsync -avze "ssh -p 10022 -i /root/.ssh/main_prv_key" /var/www/html/sites/www.ewea.org/navigation [email protected]:/var/www/html/

This is scheduled to run daily at midnight via cron

On the receiving server, the following code is then used to display the navigation on the website.

<div id="navigation">
	<?php // INCLUDE EWEA MENU
	include("/var/www/html/navigation");
	?>
</div><!-- end #navigation -->