Plugin Directory

Changeset 1393213


Ignore:
Timestamp:
04/12/2016 06:58:07 PM (10 years ago)
Author:
fduraibi
Message:

Fix bugs related to the plugin reacting to pages also

Location:
per-post-language/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • per-post-language/trunk/ppl_core.php

    r1393152 r1393213  
    77* Text Domain: perpostlanguage
    88* License:     GPLv3
    9 * Version:     1.0
     9* Version:     1.1
    1010* Author:      Fahad Alduraibi
    1111* Author URI:  http://www.fadvisor.net/blog/
     
    3737add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'ppl_add_settings_links' );
    3838
    39 function ppl_add_settings_page(){
    40     add_option( "ppl_selected_languages");
     39// Run this function once when the plugin is activated to create an entry in the database to store the settings
     40function ppl_add_options_entry(){
     41    add_option( "ppl_options"); // This is not actually needed since 'update_option" also creates the entry if it doesn't exist.
    4142}
    42 register_activation_hook( __FILE__, "ppl_add_settings_page" );
     43register_activation_hook( __FILE__, "ppl_add_options_entry" );
    4344
     45// Set the post language when loading up the page based on the store meta
    4446function ppl_set_post_language() {
    4547    $postID = url_to_postid( $_SERVER["REQUEST_URI"] );
     
    5860function ppl_save_post_meta( $post_id ) {
    5961    global $post;
    60     if( $post->post_type == "post" ) {
     62    if( isset( $post ) && $post->post_type == "post" ) {
    6163        if (isset( $_POST ) && isset($_POST['pplPostLang']) ) {
    6264            update_post_meta( $post_id, '_ppl_post_language', strip_tags( $_POST['pplPostLang'] ) );
     
    6668add_action( 'save_post', 'ppl_save_post_meta' );
    6769
     70// List of languages that are shown in the Post Language box
    6871function ppl_get_language_list( $post ) {
    6972    $postID = $post->ID;
     
    8689}
    8790
    88 function ppl_register_meta_boxes() {
     91// Post Language box is shown when editing a post, it shows on the left side by default ('high' makes it show on the top)
     92function ppl_register_meta_boxes( $post ) {
    8993    if(current_user_can( 'edit_posts' ) ){
    9094        add_meta_box( 'ppl_meta_box', esc_html__( 'Post Language', 'perpostlanguage' ), 'ppl_get_language_list', 'post', 'side', 'high', null );
    9195    }
    9296}
    93 add_action( 'add_meta_boxes', 'ppl_register_meta_boxes' );
     97add_action( 'add_meta_boxes_post', 'ppl_register_meta_boxes' );
    9498
    9599// Load plugin textdomain (translation file).
  • per-post-language/trunk/ppl_settings_page.php

    r1393152 r1393213  
    2020
    2121// Add settings page entry under WordPress default Settings menu
    22 add_action( 'admin_menu', 'ppl_settings_menu' );
    2322function ppl_settings_menu() {
    2423    add_options_page(
     
    3029    );
    3130}
     31add_action( 'admin_menu', 'ppl_settings_menu' );
    3232
    3333// The settings page for the plugin
Note: See TracChangeset for help on using the changeset viewer.