-3

I'm a beginner in Wordpress Plugin development. I want to write a Plugin for a Member Part on my Page. I know, that Plugins for this Problem available, but i want to create an own Plugin ;)

I want to create a table in the database, who looks like:

ID | PostID | MemberOnly

So, i'm searching for an filter or an action, which i can use. Up to this point, i found the filter "the_content", but i don't get the post_ID or have i overlooked something? Another action, which i found is pre_get_posts. But here are the same Problem, with the Post_ID

Anyone an idea?

Greetings

Edit: I need a possibility, where i can check the login status of the user. When i visit a page, my plugin have to check, is the visitor a guest or a logged in user. Which filter/action can i use to realize them.

Edit 2: I want to write a Plugin for a Member Area. For Sport Clubs for example. This Member have no access to the Admin Area in the Wordpress Backend. It should be an own Area. Nothing edit, only view.

In Frontend should be a Point "Only for Members". When you click on this, you see a login form (except you're logged in, then you see content). In this area you can see News ONLY for Member in this Sports Club.

So, i'm searching for an action or filter, what i can use to check, is this user logged in. When not -> go to login form -> when true -> see content

Edit 3: It should be a complete independent Member Area and uncoupled from the wp admin Members.

closed as unclear what you're asking by cybmeta, Pieter Goosen, Bainternet Dec 12 '14 at 10:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your question seems very unclear and too broad. Can you break down the problem and be more specific? – cybmeta Dec 11 '14 at 8:54
  • I need a possibility, where i can check the login status of the user. When i visit a page, my plugin have to check, is the visitor a guest or a logged in user. Which filter/action can i use to realize them. – GoatMachine Dec 11 '14 at 9:05
  • I've answered your question "I need a possibility, where i can check the login status of the user. When i visit a page, my plugin have to check, is the visitor a guest or a logged in user". But your comments bring me to nowhere. I don't understand your question and it is very unclear what you are asking. I've deleted my answer and vote for close this question. Again, please describe the exact problem you have. – cybmeta Dec 11 '14 at 11:32
  • I want to write a Plugin for a Member Area. For Sport Clubs for example. This Member have no access to the Admin Area in the Wordpress Backend. It should be an own Area. Nothing edit, only view. In Frontend should be a Point "Only for Members". When you click on this, you see a login form (except you're logged in, then you see content). In this area you can see News ONLY for Member in this Sports Club. So, i'm searching for an action or filter, what i can use to check, is this user logged in. When not -> go to login form -> when true -> see content I hope it's clear now – GoatMachine Dec 11 '14 at 12:00
  • I want to check the login status of my users in my plugin, not from the wp Admins. And i'm searching for an action/filter for this problem – GoatMachine Dec 11 '14 at 12:05
-1

You could try this:

function restricted_access() {
    if( ! is_user_logged_in() ) {
        global $wp_query;
        $wp_query->set_404();
        status_header(404);
    }
}
add_action( 'wp', 'restricted_access' );

By default, always, if the user is not logged in it will give them the 404 page. The following two functions will keep non-admins out of your Admin Panel and will also hide the black admin bar from the front-end.

function redirect_nonadmins(){
    if ( ! current_user_can( 'administrator' ) ){
        wp_redirect( site_url() );
        exit;       
    }
}
add_action( 'admin_init', 'redirect_nonadmins' );

function no_adminbar() { 
    if( ! current_user_can( 'administrator' ) ) {
        add_filter( 'show_admin_bar', '__return_false' );
    }
}
add_action( 'after_setup_theme', 'no_adminbar' );

Edit - Some explaination

The function is_user_logged_in() returns a true / false boolean; True if the user viewing the current page is logged in. False if the user viewing the current page is not logged in.

The function current_user_can() will check the current users capabilities. In the above I check if the current user has administrator capabilities. If not - do not allow them to view the admin panel and do not show the black admin bar on the front end.

  • Thanks for the answer, but it should be another Member Area. Complete uncoupled from the wp admin panel. Other Member Table. Complete independent from the admin panel. – GoatMachine Dec 11 '14 at 15:21
  • I'm not sure what you're referring to, what is completely independent from the admin panel? Are you referring to redirects? It sounds like you want somebody to code a plugin for you which makes the question very broad. If you want to write a plugin yourself you need to break down your question into small specific questions. – Howdy_McGee Dec 11 '14 at 15:22
  • My plugin members != wp members. It should be complete differently. My own user management. – GoatMachine Dec 11 '14 at 15:26
  • Specifically what's your question? Are you trying not to use WordPress functions? – Howdy_McGee Dec 11 '14 at 15:28
  • Which action/filter can i use, to check the login status. I don't know, i'm new in the Wordpress. Perhaps is my idea bad and they're better ways to realize. – GoatMachine Dec 11 '14 at 15:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.