[wp-hackers] How to use $wpdb in plugins

Leo Baiano ljunior2005 at gmail.com
Mon Jan 6 18:14:58 UTC 2014


I'm currently using calling global methods at all, I was not sure if that
was the best practice and why I sent this email.


2014/1/6 Eric Andrew Lewis <eric.andrew.lewis at gmail.com>

> I think the best practice here is to define and use the $wpdb global in
> every method you need it. You could perhaps store it by reference in a
> class variable, or create a singleton wrapper for accessing $wpdb, but both
> of these are stepping out of the “WordPress” way, and add a level of
> abstraction that isn’t adding much benefit, and perhaps confusing other
> programmers that touch your code.
>
> --
> Eric Andrew Lewis
>
>
> On Monday, January 6, 2014 at 9:58 AM, Leo Baiano wrote:
>
> > What better way to use the global $ wpdb in building a plugin? I'm
> working
> > on a plugin and some methods need to access data in the database tables,
> > including creating, and I was in doubt about the best way, like, do not
> > want to quit repeating global $ wpdb in all methods of my class.
> >
> > How do you do?
> >
> > --
> > Amplexos,
> >
> > Leo Baiano
> > Web Developer
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com (mailto:wp-hackers at lists.automattic.com)
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> >
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Amplexos,

Leo Baiano
Web Developer


More information about the wp-hackers mailing list