Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

Wordpress Function causing White screen at admin login.

Wordpress.  Class causing a White screen at login.  I have the following class.  If you are already logged in when I upload the following function, everything works fine and as intended.  However, If you are not logged in to the WP admin and I upload the following Class, when you log in you see an empty white page.  Does anyone have any idea what is wrong with my class that would be causing this?

class theleatherguy_bulk_cancel_inventory_restore {

    function __construct() {
        add_filter('bulk_actions-edit-shop_order', array($this, 'theleatherguy_register_bulk_action')); // edit-shop_order is the screen ID of the orders page
        add_action('admin_action_mark_cancel_order', array($this, 'theleatherguy_bulk_restore_order_stock'), 10, 1); // admin_action_{action name}
        add_action('admin_notices', array($this, 'theleatherguy_bulk_status_notices'));
    }

    public function theleatherguy_register_bulk_action($bulk_actions) {
        $bulk_actions['mark_cancel_order'] = 'Mark Cancel Order'; // <option value="mark_cancel_order">Bulk Cancel Order</option>
        return $bulk_actions;
    }

    public function theleatherguy_bulk_restore_order_stock() {
        // if an array with order IDs is not presented, exit the function
        if (!isset($_REQUEST['post']) && !is_array($_REQUEST['post']))
            return;

        foreach ($_REQUEST['post'] as $order_id) {
            $order = new WC_Order($order_id);
            $order_note = 'This order was part of a Bulk Cancel Process: ';
            $order->update_status('cancelled', $order_note, true);
        }

        $location = add_query_arg(array(
            'post_type' => 'shop_order',
            'mark_cancel_order' => 1, // mark_cancel_order=1 is just the $_GET variable for notices
            'changed' => count($_REQUEST['post']), // number of changed orders
            'ids' => join($_REQUEST['post'], ','),
            'post_status' => 'all'
                ), 'edit.php');

        wp_redirect(admin_url($location));
        exit;
    }

   
     * Notices
  

    function theleatherguy_bulk_status_notices() {

        global $pagenow, $typenow;

        if ($typenow == 'shop_order' && $pagenow == 'edit.php' && isset($_REQUEST['mark_cancel_order']) && $_REQUEST['mark_cancel_order'] == 1 && isset($_REQUEST['changed'])) {

            $message = sprintf(_n('Order status changed.', '%s order statuses changed.', $_REQUEST['changed']), number_format_i18n($_REQUEST['changed']));
            echo "<div class=\"updated\"><p>{$message}</p></div>";
        }
    }

}
new theleatherguy_bulk_cancel_inventory_restore();

Open in new window

Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

However, If you are not logged in to the WP admin and I upload the following Class,
Can you clarify this, please? It sounds like you're saying you're not logged into the admin area, but you're able to upload/update this file (presumably through the admin console)... Details / steps on how you're reproducing these circumstances would be helpful.

Or if I'm misunderstanding what you're saying when you say you "upload the class" - either way, more details would be helpful.

Also, make sure you turn on WP debug mode when you get the white screen. Edit your wp-config.php file and set the constant WP_DEBUG and WP_DEBUG_LOG to true:

define( 'WP_DEBUG', true );
define('WP_DEBUG_LOG', true);

Then reproduce the problem and then check the debug.log file in your wp-content folder.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skullnobrains
skullnobrains

turn on error reporting and you'll get this

PHP Parse error:  syntax error, unexpected '*', expecting function (T_FUNCTION) in /tmp/p on line 39

which is due to the "* notices" which i believe should be "# notices"

no idea why but the code is probably not loaded at all when you are admin