All posts by acrane

About acrane

A web designer from Charlotte, NC, I enjoy working in the yard, kayaking, building stuff, making things, creating, thinking and of course WordPress.

WP Admin – You do not have sufficient privileges.

To harden an old WordPress site, the first thing I did was change the table prefix to something other than wp_

But that somehow turned every user from admin to subscriber, now I was locked out. And when I tried to login, it redirected me to the homepage, not the wp-admin section. Here’s what I did:

First, grab this script, put it into a php file named, force-upgrade.php , by Mark Jaquith and upload it to the same directory as your wp-config file. Then visit that directory/force-upgrade.php It will prompt you to run the script. “Hopefully that does the trick.” – But you still need to change your permission via phpMyAdmin, skip past this script to do that.

To change your role to admin, edit the following sql script to what you need and run it in the SQL tab in phpMyAdmin

Custom Styles for your WordPress WYSIWYG

A detailed list and a guide to the TinyMCE can be found here.

Functions File

/*-------------------------------------
	Custom WYSIWYG Styles
---------------------------------------*/
function acc_custom_styles($buttons) {
	array_unshift($buttons, 'styleselect');
	return $buttons;
}
add_filter('mce_buttons_2', 'acc_custom_styles');
/*
* Callback function to filter the MCE settings
*/

function my_mce_before_init_insert_formats( $init_array ) {  

// Define the style_formats array

	$style_formats = array(  
		// Each array child is a format with it's own settings
		array(  
			'title' => 'Big Red Text',  
			'inline' => 'span',  
			'classes' => 'big-red-text',
			'wrapper' => true,
			
		)
	);  
	// Insert the array, JSON ENCODED, into 'style_formats'
	$init_array['style_formats'] = json_encode( $style_formats );  
	
	return $init_array;  
  
} 
// Attach callback to 'tiny_mce_before_init' 
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' ); 
// Add styles to WYSIWYG in your theme's editor-style.css file
function my_theme_add_editor_styles() {
    add_editor_style( 'editor-style.css' );
}
add_action( 'init', 'my_theme_add_editor_styles' );

 

css

.big-red-text {
	color: #E60000;
	font-size: 40px;
}

 

ACF Reverse Query on a Post Object

This is a slider from the index.php pulling the testimonials

<?php 
// Let's get in homepage mode.
$post = get_post(505); // My home "page" id = 505
setup_postdata( $post );
/*
	Reverse Query on the Post Object Field 
*/
$testimonials = get_posts(array(
	'post_type' => 'testimonial',
	'meta_query' => array(
		array(
			'key' => 'pages_to_show_testimonial', // name of custom field
			'value' => '"' . get_the_ID() . '"', // matches exaclty "123", 
			'compare' => 'LIKE'
		)
	)
));
// now get out of homepage mode now that we have our testimonials.
wp_reset_postdata();
if( $testimonials ): ?>
<div class="wrapper">
    <div class="testimonial">
    	<ul class="slides">
			<?php foreach( $testimonials as $testimonial ): 
            // get those id's for the fields
			 $ID = $testimonial->ID;
            $job_title = get_field( 'job_title', $ID ); 
            $company = get_field( 'company', $ID ); 
            $testimonial = get_field( 'testimonial', $ID); 
            $title = get_the_title($ID); 
            ?>
            
                <li> 
                	<div class="the-testimonial"><?php echo $testimonial; ?></div>
                	<div class="the-testimonial-name"><?php echo $title; ?></div>
                	<?php if($job_title != '' ) { echo '<div class="the-testimonial-jt">, '.$job_title.'</div>'; }?>
                	<?php if($company != '' ) { echo '<div class="the-testimonial-company">, '.$company.'</div>'; }?>  
                </li>
            
            <?php endforeach; ?>
        </ul><!-- slides -->
    </div><!-- .testimonial -->
</div><!-- wrapper -->
<?php endif; wp_reset_postdata(); ?>

 

Sortable Admin Columns with Advanced Custom Fields ACF

Add Advanced Custom Fields ACF to your admin columns in WordPress and be able to sort them.

For this I will add a custom thumbnail and Event start date for an “Event” Custom post type.

First, you need two functions. One to create the columns, overriding what was default in WordPress and one to tell what each column to do.

It’s important to note that the structure of the add_action:  ‘manage_{YOUR_POSTTYPE}_posts_custom_column’
and the structure of the filter ‘manage_edit-{YOUR_POSTTYPE}_columns’

Then this final function to sort by Event Date:

Again, note the structure of the filter:
‘manage_edit-{YOUR_POSTTYPE}_event_sortable_columns’