/** * Set default theme options. * * This function updates the theme options with the specified defaults ONLY if they don't exist. The * idea being that new theme options can be added by a developer and picked up by the theme without having * to blank the existing theme options first. If some options exist then merge current options with defaults * to set any new theme options that may have been added since last theme activation. This method does NOT * overwrite any theme options if they already exist. * * Important: Any checkboxes you need to be ON by default just add them to an array, in addition to the * $pc_default_options array, but with a "0" value. Otherwise when the theme is deactivated/reactivated the ON by * default checkboxes will always be set to ON even if the user set to off in the meantime. This is because if * a check box is turned off it is not stored in the options db at all, but to be efectively tested by the * array_merge($pc_default_options, $current_options) function, if it has been turned off by the user then it * needs to be set to zero manually in the code. * * @since 0.1.0 */ public function default_theme_options() { /* Define as global to accessible anywhere (i.e. from within hook callbacks). */ global $pc_default_options, $pc_footer_links; /* Define some theme specific option constants. */ define("PC_ADMIN_EMAIL_TEXTBOX", "txt_admin_email"); define("PC_SEO_SETTINGS_CHECKBOX", "chk_seo_settings"); define("PC_DEFAULT_LAYOUT_THEME_OPTION", "drp_default_layout"); define("PC_LOGO_URL_OPTION_NAME", "txt_logo_url"); // logo url text box define("PC_LOGO_CHK_OPTION_NAME", "chk_custom_logo"); // logo checkbox (to use/not use a custom logo) /* @todo Add footer links in via a (theme specific) hook cb only if the footer theme options are used. */ $footer_theme_name = PC_THEME_NAME == 'Designfolio Pro' ? 'designfolio' : PC_THEME_NAME; $pc_footer_links = '<div id="site-info"><p class="copyright">© [year] [site-url]</p><p class="pc-link">Powered by <a href="http://wordpress.org/" target="_blank" class="wp-link">WordPress</a> and the <a href="http://www.presscoders.com/' . $footer_theme_name . '/" target="blank" title="' . PC_THEME_NAME . ' WordPress Theme">' . PC_THEME_NAME . ' Theme</a>.</p></div><!-- #site-info -->'; /* Defaults options array. */ $pc_default_options = array(PC_LOGO_CHK_OPTION_NAME => null, PC_LOGO_URL_OPTION_NAME => "", "chk_hide_description" => null, PC_DEFAULT_LAYOUT_THEME_OPTION => "2-col-r", "chk_show_social_buttons" => "1", PC_SEO_SETTINGS_CHECKBOX => null, PC_ADMIN_EMAIL_TEXTBOX => get_bloginfo('admin_email'), "txtarea_header" => "", "txtarea_footer" => "", "txtarea_footer_links" => $pc_footer_links, "txt_favicon" => "", "txtarea_custom_css" => ""); /* Get a copy of the current theme options. */ $current_options = get_option(PC_OPTIONS_DB_NAME); /* If theme options not set yet then don't bother trying to merge with the $pc_default_off_checkboxes. */ if (is_array($current_options)) { /* Define as global to accessible anywhere (i.e. from within hook callbacks). */ global $pc_default_off_checkboxes; $pc_default_off_checkboxes = array("chk_show_social_buttons" => "0"); } /* Add theme specific default settings vis this hook. */ PC_Hooks::pc_theme_option_defaults(); /* Framework hook wrapper */ /* Added this here rather inside the same 'if' statement above so we can add extra $pc_default_off_checkboxes via a hook. */ if (is_array($current_options)) { /* Manually set the checkboxes that have been unchecked, by the user, to zero. */ $current_options = array_merge($pc_default_off_checkboxes, $current_options); } /* If there are no existing options just use defaults (no merge). */ if (!$current_options || empty($current_options)) { // Update options in db update_option(PC_OPTIONS_DB_NAME, $pc_default_options); } else { /* Merge current options with the defaults, i.e. add any new options but don't overwrite existing ones. */ $result = array_merge($pc_default_options, $current_options); /* Update options in db. */ update_option(PC_OPTIONS_DB_NAME, $result); } }