Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:42:49+00:00 2026-06-15T12:42:49+00:00

I want to be able to access WordPress’ functions from a CakePHP controller. I

  • 0

I want to be able to access WordPress’ functions from a CakePHP controller. I tried this from an action:

require_once('path/to/wp-load.php');

It was needed to make a few changes on WP core to avoid re-declaring a couple of functions that WP and CakePHP have in common.

But I am still getting an error:

Strict (2048): Redefining already defined constructor for class WP_Widget [APP\webroot\WP\wp-includes\widgets.php, line 93]

Despite the error, if I call The Loop it works. Calling wp_insert_post() also works. Basically I already have access to WP functions. But that redefining error won’t go away.

I tried this:

error_reporting(-1);
Configure::write('debug', 0);

But both didn’t help.

  • Any idea how to get rid of that warning?
  • Is there a correct way to make CakePHP to extend WordPress functions?

I found this component (shama/CakePHP-Wordpress-Component), however the last change was 2 years ago and the author announced 3 months ago that the component is deprecated. Also, it makes use of cURL to interact with WP API. I just want to extend it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:42:50+00:00Added an answer on June 15, 2026 at 12:42 pm

    I found a solution. Not sure if it is the right way to do it. I’m gonna post the whole thing in case someone wants to do the same.

    Keep in mind that this was the solution I came up with. I think this is breaking the MVC workflow in so many levels that you should use this workaround at your own risk.

    1. Install WordPress normally in a sub-folder inside /app/webroot/
    2. In the controller, within the action, you want to use WP functions you call this:

      require_once('full/path/to/wp-load.php');

    3. Call the action to see if there is any conflict. In my case the functions __() and stripslashes_deep() existed in both. So, I had to avoid re-declaring them.

      if(!function_exists('FUNCTION_NAME_HERE')) { function ... }

    4. At this point, you can already access WP functions inside your controller. But that problem with WP_Widget class will probably fire a warning. So, here is how you fix it:

      4.1 Open wp-settings.php (it is in WP’s root) and comment these lines:

      require( ABSPATH . WPINC . '/widgets.php' );

      $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();

      4.2 Open wp-includes/functions.php and comment this line:

      require_once( ABSPATH . WPINC . '/default-widgets.php' );

      4.3 Open wp-content/themes/twentyeleven/inc/functions.php and comment:

      require( get_template_directory() . '/inc/widgets.php' );

    You can now call WP normally from inside the action like you would do in a WP theme:

    query_posts('showposts=10');
    while (have_posts()):
        the_title();
    endwhile;
    

    Requiring wp-load.php on beforeFilter() does not seem to work, unless you do all the WP work inside beforeFilter() and save the results in a variable. Otherwise CakePHP seems to unload wp-load.php when moving to the action and you can no longer access WP functions.

    It would probably work too if converting this hack into a component and then you could access WP with something like $this->Wordpress->query_posts('showposts=10');

    Admin is broken

    This is due to step 4, when we commented out all the widgets functions. In order to fix it, you will have to include a condition like this:

    if (is_admin()) {
       require( ABSPATH . WPINC . '/widgets.php' );
    }
    

    This condition, of course, must be applied on all the lines commented in step 4. If you won’t use WP admin area, you don’t need to use this condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to access properties from a JSON string within my
I want to be able to access the array directly from the return value
Very simply, I want to be able to access the year from the select
I have this coding. I want to be able to access say Data Extraction
Ok, I want to be able to access certain variables from anywhere within a
I have this url: http://mysite.com/home.php?name=username I want to be able to access that by
Normally I access a page like this: http://localhost/codeigniter/index.php/auth/login However I want to be able
I want to be able to access classes further up the dom tree from
Suppose I have a hierarchy of functions, I want to be able to access
I want to be able to access my development server from a machine outside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.