示例#1
0
function hocwp_register_string_language($args = array())
{
    if (!did_action('init')) {
        _doing_it_wrong(__FUNCTION__, __('Please call this function in <strong>hocwp_register_string_translation</strong> hook.', 'hocwp-theme'), HOCWP_VERSION);
        return;
    }
    if (!is_array($args)) {
        $args = array('string' => $args);
    }
    $name = hocwp_get_value_by_key($args, 'name');
    $string = hocwp_get_value_by_key($args, 'string');
    $context = hocwp_get_value_by_key($args, 'context', 'HocWP');
    $multiline = hocwp_get_value_by_key($args, 'multiline');
    $key = md5($string);
    $active_strings = hocwp_get_active_registered_string_language();
    $active_strings[$key]['name'] = $name;
    $active_strings[$key]['string'] = $string;
    $active_strings[$key]['context'] = $context;
    $active_strings[$key]['multiline'] = $multiline;
    global $hocwp_active_registered_string_translations;
    $hocwp_active_registered_string_translations = $active_strings;
    $transient_name = hocwp_build_transient_name('hocwp_string_translation_registered_%s', $args);
    if (false === get_transient($transient_name)) {
        $strings = hocwp_get_registered_string_language();
        $strings[$key]['name'] = $name;
        $strings[$key]['string'] = $string;
        $strings[$key]['context'] = $context;
        $strings[$key]['multiline'] = $multiline;
        update_option('hocwp_string_translations', $strings);
        $mo = new HOCWP_MO();
        $translation = '';
        $object = $mo->get_object($string);
        if (is_a($object, 'WP_Post')) {
            $translation = $object->post_content;
        }
        $post_id = $mo->export_to_db($string, $translation);
        if (hocwp_id_number_valid($post_id)) {
            set_transient($transient_name, $post_id, WEEK_IN_SECONDS);
        }
    }
}