korvinm / pp-keep Goto Github PK
View Code? Open in Web Editor NEWWordPressPlugin modifying how Private Posts are displayed
WordPressPlugin modifying how Private Posts are displayed
=== Private Posts Keep === == Description == Essentially the intent is to segregate private posts. Removes private posts from the main query on the posts Page, adds a widget and creates a Page for holding private posts. On single post views, post navigation is filtered to show only posts from the same status. == NB == This is not complete. == Acknowledgments == The WordPress community
The if statement
if( current_user_can( 'read_private_posts' ) ){
//do something
}
is used twice in the plugin. First in the class PPKeep to wrap the contents of the function rem_pp()
and secondly in the class PP_Keep_Widget to wrap the contents of the function widget() so that the widget is not output on the front end for users without that capability.
How can this be refactored so the if statement only needs using once?
The class PPKeep has a function, create() which creates a page.
The function returns a variable like so:
$insert_post = wp_insert_post( $post, true);//now you can use $post_id within add_post_meta or update_post_meta
return $insert_post;
There are a couple of places elsewhere in the plugin where I am interacting with this page.
in the class PP_Keep_Widget, the widget includes a link to the page.
In the deactivation hook I am deleting the page. In both cases I am getting the page using the page title. However this depends on the user neither changing the title nor deleting the page, which cannot be guaranteed. I'm not coding defensively, as the saying goes.
I would really like to access the return variable from the create() function instead as at least using the ID of the post would be a bit more like it. It wouldn't defend against the user deleting the page but it would still work if the user has changed the page title.
But I don't know how to access the variable outside the class.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.