Class: WordPress::Options
Instance Method Summary collapse
Methods inherited from Base
#get_post_meta, #get_the_terms, #initialize, #insert, #inspect, #set_post_meta, #set_post_terms, #update, #update_or_insert
Constructor Details
This class inherits a constructor from WordPress::Base
Instance Method Details
#[](key) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/wordpress/options.rb', line 4 def [](key) v = nil @conn.query("SELECT `option_value` FROM `#{@tbl[:options]}` WHERE `option_name`='#{@conn.escape key}' LIMIT 1").each do |row| v = row[:option_value] end v end |
#[]=(key, value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wordpress/options.rb', line 12 def []=(key, value) old_value = nil @conn.query("SELECT `option_value` FROM `#{@tbl[:options]}` WHERE `option_name`='#{@conn.escape key}' LIMIT 1").each do |row| old_value = row[:option_value] end if !value.nil? and !old_value.nil? and value != old_value # Update operation. @conn.query("UPDATE `#{@tbl[:options]}` SET `option_value`='#{@conn.escape value}' WHERE `option_name`='#{@conn.escape key}'") elsif value.nil? and !old_value.nil? # New value nil, old value not. Delete operation. @conn.query("DELETE FROM `#{@tbl[:options]}` WHERE `option_name`='#{@conn.escape key}'") elsif !value.nil? and old_value.nil? # New value non-nil, old value nil. Insert operation. @conn.query("INSERT INTO `#{@tbl[:options]}` (`option_name`, `option_value`, `autoload`) VALUES ('#{@conn.escape key}', '#{@conn.escape value.to_s}', 'no')") end value end |